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 : 'c -> Fiber.t -> (Fiber.t -> unit) -> unit;
  3. yield : 'c -> unit;
  4. cancel_after : 'a. 'c -> 'a Computation.t -> seconds:float -> exn -> Printexc.raw_backtrace -> unit;
  5. await : 'c -> Trigger.t -> (exn * Printexc.raw_backtrace) 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 -> (Fiber.t -> unit) -> unit

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

ℹ️ 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.