Legend:
Library
Module
Module type
Parameter
Class
Class type
Concurrency library
Generals
type'a t
Type of fiber. A fiber represent a suspended computation. Note that using the same fiber twice will execute it twice, which is probably not what you want. To share the result of a fiber, use an Ivar.t.
val sequential_map : 'a list->f:('a->'bt)->'b listt
val sequential_iter : 'a list->f:('a->unit t)->unit t
Forking + joining
The following functions combine forking 2 or more fibers followed by joining the results. For every function, we give an equivalent implementation using the more basic functions as documentation. Note however that these functions are implemented as primitives and so are more efficient that the suggested implementation.
val fork_and_join : (unit ->'at)->(unit ->'bt)->('a * 'b)t
For two fibers and wait for their results:
let fork_and_join f g =
fork f >>= fun a ->
fork g >>= fun b -> both (Future.wait a) (Future.wait b)
val fork_and_join_unit : (unit ->unit t)->(unit ->'at)->'at
Same but assume the first fiber returns unit:
let fork_and_join_unit f g =
fork f >>= fun a ->
fork g >>= fun b -> Future.wait a >>> Future.wait b
val fork_and_race :
(unit ->'at)->(unit ->'bt)->('a, 'b)Stdune.Either.tt
with_error_handler f ~on_error calls on_error for every exception raised during the execution of f. This include exceptions raised when calling f () or during the execution of fibers after f () has returned. Exceptions raised by on_error are passed on to the parent error handler.
It is guaranteed that after the fiber has returned a value, on_error will never be called.
fold_errors f ~init ~on_error calls on_error for every exception raised during the execution of f. This include exceptions raised when calling f () or during the execution of fibers after f () has returned.
Exceptions raised by on_error are passed on to the parent error handler.