package brr
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=49e7bfbad2ea6a0139354e4a33c59c8a113c4c1e20a4f629bc5cad24aa801e474b4af10ce35adbda5d23dd294d1de5efa5b10bb3030d03f4758459977250a0f6
doc/brr/Fut/index.html
Module 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.
Future values do not support exceptions, you need to turn them into a value and make them appear in the future's type, for example using Fut.error.
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. fn must not raise.
bind f fn is the future fn v with v the value determined by f. fn must not raise.
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.