package prr
Install
Dune Dependency
Authors
Maintainers
Sources
md5=af96abcfdbe77859be0feae50ab64ceb
sha512=ae01bbfebc2631839afe970f587e065e055cab944fcc29cec3feb0c91ce39eda0bd347cb5546f8efa5dd7766a73d71b9d41cc3b89211d20b58829f2732f8314b
doc/prr/Prr/Fut/index.html
Module Prr.Fut
Source
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
The type for futures with value of type 'a
.
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.
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.
map fn f
is return (fn v)
with v
the value determined by f
.
bind f fn
is the future fn v
with v
the value determined by f
.
pair f0 f1
is the future that determines with the value of f0
and f1
.
of_list fs
determines with the values of all future fs
in the same order.
tick ~ms
determines ()
ms
milliseconds after creation using setTimeout
.
Future results
The type for future values that error with a JavaScript error.
Converting with JavaScript promises
of_promise ~ok p
is of_promise' ~ok ~error:Jv.to_error. p
.
to_promise p
is to_promise' ~ok ~error:Jv.of_error p
.
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
.
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
Future result syntax.