Fiber.MaybeAn unboxed optional fiber.
val nothing : tNot a fiber.
of_fiber fiber casts the fiber into an optional fiber.
🏎️ This performs no allocations.
val current_if : bool option -> tcurrent_if checked returns nothing in case checked is Some false and otherwise of_fiber (Fiber.current ()).
val current_and_check_if : bool option -> tcurrent_check_if checked returns nothing in case checked is Some false and otherwise of_fiber (Fiber.current ()) and also calls Fiber.check on the fiber.
or_current maybe returns of_fiber (Fiber.current ()) in case maybe is nothing and otherwise returns maybe.
to_fiber_or_current maybe returns Fiber.current () in case maybe is nothing and otherwise returns the fiber that maybe was cast from.
val check : t -> unitcheck maybe returns immediately if maybe is nothing and otherwise calls Fiber.check on the fiber.
equal l r determines whether l and r are maybe equal. Specifically, if either l or r or both is nothing, then they are considered (maybe) equal. Otherwise l and r are compared for physical equality.
equal l r determines whether l and r are maybe unequal. Specifically, if either l or r or both is nothing, then they are considered (maybe) unequal. Otherwise l and r are compared for physical equality.
The fiber identity is often needed only for the purpose of dynamically checking against programming errors. Unfortunately it can be relative expensive to obtain the current fiber.
As a data point, in a benchmark that increments an int ref protected by a mutex, obtaining the fiber identity for the lock and unlock operations — that only need it for error checking purposes — roughly tripled the cost of an increment on a machine.
Using GADTs internally allows an optional fiber to be provided without adding overhead to operations on non-optional fibers and allows optional fibers to used without allocations at a very low cost.