package prr

  1. Overview
  2. Docs
A fork of brr, sans browser-only APIs

Install

Dune Dependency

Authors

Maintainers

Sources

0.1.1.tar.gz
md5=af96abcfdbe77859be0feae50ab64ceb
sha512=ae01bbfebc2631839afe970f587e065e055cab944fcc29cec3feb0c91ce39eda0bd347cb5546f8efa5dd7766a73d71b9d41cc3b89211d20b58829f2732f8314b

doc/prr/Prr/Fut/index.html

Module Prr.FutSource

Future values.

A future 'a Fut.t is an undetermined value of type 'a that becomes determined at an arbitrary point in the future. The future acts as a placeholder for the value while it is undetermined.

Brr uses future values ('a, 'b) result Fut.t to type the resolution and rejection case of JavaScript promises. Since most rejection cases given by browser APIs are simply Jv.Error.t values, the dedicated Fut.or_error type alias can be used for that.

Fut.t values are indirectly implemented as Promise objects that never reject. You can't substitute them directly for JavaScript promises and vice-versa, use of_promise and to_promise to convert between them.

Futures

Sourcetype 'a t

The type for futures with value of type 'a.

Sourceval create : unit -> 'a t * ('a -> unit)

create () is (f, set with f the future value and set the function to set it. The latter can be called only once, a Jv.Error is thrown otherwise.

Sourceval await : 'a t -> ('a -> unit) -> unit

await f k waits for f to determine v and continues with k v. If the future never determines k is not invoked. k must not raise.

Sourceval return : 'a -> 'a t

return v is a future that determines v.

Sourceval map : ('a -> 'b) -> 'a t -> 'b t

map fn f is return (fn v) with v the value determined by f.

Sourceval bind : 'a t -> ('a -> 'b t) -> 'b t

bind f fn is the future fn v with v the value determined by f.

Sourceval pair : 'a t -> 'b t -> ('a * 'b) t

pair f0 f1 is the future that determines with the value of f0 and f1.

Sourceval of_list : 'a t list -> 'a list t

of_list fs determines with the values of all future fs in the same order.

Sourceval tick : ms:int -> unit t

tick ~ms determines () ms milliseconds after creation using setTimeout.

Future results

Sourcetype nonrec ('a, 'b) result = ('a, 'b) result t

The type for future values that may error.

Sourcetype 'a or_error = ('a, Jv.Error.t) result

The type for future values that error with a JavaScript error.

Sourceval ok : 'a -> ('a, 'b) result

ok v is return (Ok v).

Sourceval error : 'b -> ('a, 'b) result

error e is return (Error e).

Converting with JavaScript promises

Sourceval of_promise : ok:(Jv.t -> 'a) -> Jv.Promise.t -> 'a or_error

of_promise ~ok p is of_promise' ~ok ~error:Jv.to_error. p.

Sourceval to_promise : ok:('a -> Jv.t) -> 'a or_error -> Jv.Promise.t

to_promise p is to_promise' ~ok ~error:Jv.of_error p.

Sourceval of_promise' : ok:(Jv.t -> 'a) -> error:(Jv.t -> 'b) -> Jv.Promise.t -> ('a, 'b) result

of_promise ~ok ~error p is a future for the promise p. The future determines with Ok (ok v) if p resolves with v and with Error (error e) if p rejects with e.

Sourceval to_promise' : ok:('a -> Jv.t) -> error:('b -> Jv.t) -> ('a, 'b) result -> Jv.Promise.t

to_promise f is a JavaScript promise for the future f that resolves the promise with ok v if the future determines with Ok v and rejects with e if the future determines with Error e.

Future syntaxes

Sourcemodule Syntax : sig ... end

Future syntax.

Sourcemodule Result_syntax : sig ... end

Future result syntax.

OCaml

Innovation. Community. Security.