package fuseau

  1. Overview
  2. Docs

Fibers.

A fiber is a lightweight cooperative thread. It runs on the scheduler and can yield to other fibers, notably on IO polling points.

type 'a t

A fiber returning a value of type 'a.

type any =
  1. | Any_fiber : _ t -> any

A fiber with erased return type.

type 'a callback = 'a Exn_bt.result -> unit

Callbacks that are called when a fiber is done.

type cancel_callback = Exn_bt.t -> unit
val return : 'a -> 'a t
val fail : Exn_bt.t -> _ t
val peek : 'a t -> 'a Exn_bt.result option
val is_cancelled : _ t -> bool
val is_done : _ t -> bool
exception Cancelled of Exn_bt.t

Exception for fibers that are cancelled. Polling points such as yield and await will raise this if the fiber has been cancelled.

val on_res : 'a t -> 'a callback -> unit

Wait for fiber to be done and call the callback with the result. If the fiber is done already then the callback is invoked immediately with its result.

val get_current : unit -> any

get_current () returns the currently running fiber.

  • raises Failure

    if called from outside a fiber

OCaml

Innovation. Community. Security.