Module 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 joins. 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.

val bind : t -> ('a -> t) -> t

bind p fn binds p's resolution to function fn.

val then' : t -> ('a -> t) -> ('b -> t) -> t

then' p res rej binds p's resolution to res and p's rejection to rej.

val all : jv -> t

all arr is a promise that resolves all the promises in the array arr to an array of values.