Jv.Promise
JavaScript promise support.
In bindings do not use this directly use Fut
.
type t = jv
The type for JavaScript promises.
val create : (('a -> unit) -> ('b -> unit) -> unit) -> t
create (fun res rej -> ...)
is a promise that can be resolved with res
and rejected with rej
. Note that res
has a weird semantics see resolve
for details.
val resolve : 'a -> t
resolve v
is a promise that resolve with v
. Warning. this is not a monadic return
it also join
s. Use Fut
for a sound typed semantics of promises.
val reject : 'a -> t
reject v
is a promise that rejects with v
.
val await : t -> ('a -> unit) -> unit
await p k
waits for p
to resolve and continues with k
.
then' p res rej
binds p
's resolution to res
and p
's rejection to rej
.