package picos

  1. Overview
  2. Docs

Handler for the effects based operations of Picos for OCaml 4.

type 'c t = {
  1. current : 'c -> Fiber.t;
  2. spawn : 'a. 'c -> forbid:bool -> 'a Computation.t -> (unit -> unit) list -> unit;
  3. yield : 'c -> unit;
  4. cancel_after : 'a. 'c -> 'a Computation.t -> seconds:float -> Exn_bt.t -> unit;
  5. await : 'c -> Trigger.t -> Exn_bt.t option;
}

A record of implementations of the primitive effects based operations of Picos. The operations take a context of type 'c as an argument.

val using : 'c t -> 'c -> (unit -> 'a) -> 'a

using handler context thunk sets the handler and the context for the handler of the primitive effects based operations of Picos while running thunk.

ℹ️ The behavior is that

  • on OCaml 4, using stores the handler in TLS, which allows the operations to be accessed during the execution of the thunk, and
  • on OCaml 5, using runs thunk with a deep effect handler that delegates to the operations of the handler.

⚠️ While this works on OCaml 5, you usually want to use a scheduler that implements an effect handler directly, because that is likely to perform better.

OCaml

Innovation. Community. Security.