Module Picos_std_structured.Run

Operations for running fibers in specific patterns.

val all : (unit -> unit) list -> unit

all actions starts the actions as separate fibers and waits until they all complete or one of them raises an unhandled exception other than Terminate, which is not counted as an error, after which the remaining fibers will be canceled.

⚠️ 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 unhandled exception 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.

val any : (unit -> unit) list -> unit

any actions starts the actions as separate fibers and waits until one of them completes or raises an unhandled exception other than Terminate, which is not counted as an error, after which the rest of the started fibers will be canceled.

⚠️ 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 unhandled exception 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.