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 α
can now be passed aroundpromise.result.get
blocks until the promise is resolvedpromise.resolve a
resolves the promisepromise.result.get
now returnsa
Every promise must eventually be resolved. Otherwise the memory used for the promise will be leaked, and any tasks depending on the promise's result will wait forever.
Equations
- IO.Promise α = (IO.PromiseImpl α).val
Instances For
@[extern lean_io_promise_new]
Creates a new Promise
.
@[extern lean_io_promise_resolve]
Resolves a Promise
.
Only the first call to this function has an effect.
@[implemented_by _private.Init.System.Promise.0.IO.Promise.resultImpl]
The result task of a Promise
.
The task blocks until Promise.resolve
is called.