Promise α
allows you to create a Task α
whose value is provided later by calling resolve
.
Typical usage is as follows:
let promise ← Promise.new
creates a promisepromise.result? : Task (Option α)
can now be passed aroundpromise.result?.get
blocks until the promise is resolvedpromise.resolve a
resolves the promisepromise.result?.get
now returnssome a
If the promise is dropped without ever being resolved, promise.result?.get
will return none
.
See Promise.result!/resultD
for other ways to handle this case.
Equations
Instances For
Like Promise.result
, but resolves to none
if the promise is dropped without ever being resolved.
The result task of a Promise
.
The task blocks until Promise.resolve
is called. If the promise is dropped without ever being
resolved, evaluating the task will panic and, when not using fatal panics, block forever. As
Promise.result!
is a pure value and thus the point of evaluation may not be known precisely, this
means that any promise on which Promise.result!
may be evaluated must be resolved eventually.
When in doubt, always prefer Promise.result?
to handle dropped promises explicitly.
Equations
- promise.result! = Task.map IO.Option.getOrBlock!✝ promise.result? Task.Priority.default true
Instances For
The result task of a Promise
.
The task blocks until Promise.resolve
is called. If the promise is dropped without ever being
resolved, evaluating the task will panic and, when not using fatal panics, block forever. As
Promise.result!
is a pure value and thus the point of evaluation may not be known precisely, this
means that any promise on which Promise.result!
may be evaluated must be resolved eventually.
When in doubt, always prefer Promise.result?
to handle dropped promises explicitly.
Equations
Instances For
Like Promise.result
, but resolves to dflt
if the promise is dropped without ever being resolved.
Equations
Instances For
Checks whether the promise has already been resolved, i.e. whether access to result*
will return
immediately.
Equations
- promise.isResolved = IO.hasFinished promise.result?