Picos_std_structured.Run
Operations for running fibers in specific patterns.
all actions
starts the actions as separate fibers and waits until they all return. If any of the actions raises an exception other than Terminate
the remaining fibers will be canceled and the exception, if any, will be raised.
⚠️ One of the actions may be run on the current fiber.
⚠️ It is not guaranteed that any of the actions in the list are called. In particular, after any action raises an exception other than Terminate
or after the main fiber is canceled, the actions that have not yet started may be skipped entirely.
all
is roughly equivalent to
let all actions =
Bundle.join_after @@ fun bundle ->
List.iter (Bundle.fork bundle) actions
but treats the list of actions as a single computation.
any actions
starts the actions as separate fibers and waits until one of them returns or raises an exception other than Terminate
after which the remaining started fibers will be canceled and the exception, if any, will be raised.
⚠️ One of the actions may be run on the current fiber.
⚠️ It is not guaranteed that any of the actions in the list are called. In particular, after the first action returns successfully or after any action raises an exception other than Terminate
or after the main fiber is canceled, the actions that have not yet started may be skipped entirely.
any
is roughly equivalent to
let any actions =
Bundle.join_after @@ fun bundle ->
try
actions
|> List.iter @@ fun action ->
Bundle.fork bundle @@ fun () ->
action ();
Bundle.terminate bundle
with Control.Terminate -> ()
but treats the list of actions as a single computation.
first_or_terminate actions
starts the actions as separate fibers and waits until one of them returns a value or raises an exception other than Terminate
after which the remaining started fibers will be canceled and the value will be returned or the exception, if any, will be raised. If none of the actions returned or raised an exception other than Terminate
, then Terminate
will be raised.
⚠️ One of the actions may be run on the current fiber.
⚠️ It is not guaranteed that any of the actions in the list are called. In particular, after the first action returns successfully or after any action raises an exception other than Terminate
or after the main fiber is canceled, the actions that have not yet started may be skipped entirely.