Promise

From Erights

(Difference between revisions)
Jump to: navigation, search
(Calls and sends: tests were broken: 1 never returned, and had a stray <Promise> -- checking resolve's value instead)
(make stub)
Line 1: Line 1:
-
A [[promise]], in [[E]], is a kind of [[unresolved ref|unresolved]] [[eventual ref]]. It is a [[ref]] which will [[resolve]] to some other ref later; therefore all [[send]]s it receives are stored, then forwarded at the time of the resolution. Every promise has a corresponding [[resolver]] (though it might be implicit), which constitutes the [[permission]] to cause it to resolve to a given other reference (which may itself be a promise).
+
A [[promise]], in [[E]], is a [[ref]] whose referent has not yet been determined -- it is an [[ref states|unresolved reference]].
-
A '''local promise''' is a promise whose resolver is in this vat; local promises are reliably implemented by the local [[ELib]]. A [[remote promise]] is a promise whose resolver is in a different [[vat]]; remote promises are implemented by [[Proxy|proxies]].
+
Every promise has a corresponding [[resolver]] (though it may not be explicitly used), which constitutes the [[permission]] to cause it to resolve to a given other reference (which may itself be a promise).
-
==Local promises==
+
Promises are often created by performing [[eventual send]]s or by explicit [[Ref (object)#promise/0|promise pair creation]].
-
The general-purpose operation to create a local promise is [[Object Ref#promise/0|Ref#promise/0]].
+
A [[remote promise]] is a promise whose resolver is in a different [[vat]].
-
? def [promise, resolver] := Ref.promise()
+
{{stub}}
-
# value: [<Promise>, <Resolver>]
+
-
+
-
? Ref.state(promise)
+
-
# value: "EVENTUAL"
+
-
+
-
? Ref.isResolved(promise)
+
-
# value: false
+
-
 
+
-
Once a promise (local or remote) is resolved, it is indistinguishable from the reference which it is resolved to, whether that reference is [[Selfless]],
+
-
 
+
-
? resolver.resolve(99)
+
-
+
-
? promise
+
-
# value: 99
+
-
+
-
? promise + 1
+
-
# value: 100
+
-
+
-
? promise == 99
+
-
# value: true
+
-
 
+
-
or [[Selfish]].
+
-
 
+
-
? def [promise, resolver] := Ref.promise()
+
-
> resolver.resolve(def x {})
+
-
> promise == x
+
-
# value: true
+
-
 
+
-
{{XXX}} write tests and doc from the LocalResolver's perspective (isDone, resolveRace/smash, behavior after it is resolved) -- EoCL has some in ref.updoc
+
-
 
+
-
==Calls and sends==
+
-
 
+
-
? def [promise, resolver] := Ref.promise(); null
+
-
 
+
-
As with any [[unresolved ref]], a promise cannot be [[call]]ed.
+
-
 
+
-
? promise(1)
+
-
# problem: not synchronously callable: <Promise>.run(1)
+
-
 
+
-
However, any [[send]]s to the promise are accepted and buffered in the resolver, in time order.
+
-
 
+
-
? promise <- (2)
+
-
# value: <Promise>
+
-
+
-
? E.sendOnly(promise, "run", [3])
+
-
 
+
-
If the resolver becomes garbage, then so does the buffer; future messages to the promise are silently discarded and do not accumulate. Note that this implies that the promise does not [[strongly refer to]] the resolver. ({{XXX}} write tests for this using finalizers.)
+
-
 
+
-
At the instant a local promise is resolved to another ref (which is known as its [[resolution]]), the buffered messages are sent, in the order they arrived, to the resolution.
+
-
 
+
-
? var items := []
+
-
> def resolution(x) { items with= x }
+
-
> resolution <- (4)            # demonstrating exact ordering
+
-
> def resolveReturn := resolver.resolve(resolution)
+
-
> resolution <- (5)
+
-
> resolveReturn
+
-
+
-
? items
+
-
# value: [4, 2, 3, 5]
+
-
 
+
-
[[Category:ELib_specification]]
+

Revision as of 19:20, 14 October 2008

A promise, in E, is a ref whose referent has not yet been determined -- it is an unresolved reference.

Every promise has a corresponding resolver (though it may not be explicitly used), which constitutes the permission to cause it to resolve to a given other reference (which may itself be a promise).

Promises are often created by performing eventual sends or by explicit promise pair creation.

A remote promise is a promise whose resolver is in a different vat.

This page is a stub; it should be expanded with more information. If doing so, check the original E web site and the mailing list archives for content which could be moved into this page.
Personal tools
more tools