package kcas_data
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=098ce4a218d056de19124cfe2a3bb4fe611467adb65325bbe5ce18ae05cd0cdc
sha512=1c96a9eb0230d9a9134fab358cb6e5112c51e912d3000f777256d5610fa3834d52ecb58843efe1dbb212440d233dca28f62d69665f9b86332c7ae5ae03f7f2ad
doc/kcas_data/Kcas_data/Promise/index.html
Module Kcas_data.Promise
Source
A promise of a value to be resolved at some point in the future.
Example:
# let promise, resolver = Promise.create () in
let domain = Domain.spawn @@ fun () ->
Printf.printf "Got %d\n%!" (Promise.await promise)
in
Promise.resolve resolver 42;
Domain.join domain
Got 42
- : unit = ()
Common interface
The type of a promise of a value of type 'a
.
The type of a resolver of a value of type 'a
.
The type of a promise of a result of type ('a, exn) result
.
create ()
returns a new unresolved pair of a promise and a resolver for the promise.
create_resolved x
returns a promise that is already resolved to the given value x
.
Compositional interface
Non-compositional interface
resolve u v
resolves the promise corresponding to the resolver u
to the value v
. Any awaiters of the corresponding promise are then unblocked.
await t
either immediately returns the resolved value of the promise t
or blocks until the promise t
is resolved.
peek t
immediately returns either the resolved value of the promise t
or None
in case the promise hasn't yet been resolved.
is_resolved t
determines whether the promise t
has already been resolved.
Result promises
await_exn t
is equivalent to match await t with v -> v | exception e -> raise e
.
resolve_ok u v
is equivalent to resolve u (Ok v)
.