package eio
Build not yet checkedInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=a9771c0d7f4d9d9fe17badd3d147c96e85f34410ab252119ade2a407ab41ccb5
sha512=a6e0bfdc7d48886b613ba70004a46309e4162f6109d9603fbe9d70dafcc4fad3cd2382998685b1db4bb8e5bf0bbc89371b9023644d3bfaa80757e5e6939c6d8e
doc/eio/Eio/Promise/index.html
Module Eio.PromiseSource
A promise is a placeholder for result that will arrive in the future.
Unlike lazy values, you cannot "force" promises; a promise is resolved when the maker of the promise is ready.
Promises are thread-safe and so can be shared between domains and used to communicate between them.
Example:
let promise, resolver = Promise.create () in
Fiber.both
(fun () -> traceln "Got %d" (Promise.await promise))
(fun () -> Promise.resolve resolver 42)An 'a t is a promise for a value of type 'a.
An 'a u is a resolver for a promise of type 'a.
create () is a fresh promise/resolver pair. The promise is initially unresolved.
create_resolved x is a promise that is already resolved with result x.
await t blocks until t is resolved. If t is already resolved then this returns immediately.
resolve u v resolves u's promise with the value v. Any threads waiting for the result will be added to the run queue.
try_resolve is like resolve but returns false instead of raising Invalid_argument.
Returns true on success.
peek t is Some v if the promise has been resolved to v, or None otherwise. If the result is None then it may change in future, otherwise it won't. If another domain has access to the resolver then the state may have already changed by the time this call returns.