Picos_std_sync.Lazy
A lazy suspension.
âšī¸ This intentionally mimics the interface of Stdlib.Lazy
. Unlike with the standard library suspensions an attempt to force a suspension from multiple fibers, possibly running on different domains, does not raise the Undefined
exception.
val from_fun : (unit -> 'a) -> 'a t
from_fun thunk
returns a suspension.
val from_val : 'a -> 'a t
from_val value
returns an already forced suspension whose result is the given value
.
val is_val : 'a t -> bool
is_val susp
determines whether the suspension has already been forced and didn't raise an exception.
val force : 'a t -> 'a
force susp
forces the suspension, i.e. computes thunk ()
using the thunk
passed to from_fun
, stores the result of the computation to the suspension and reproduces its result. In case the suspension has already been forced the computation is skipped and stored result is reproduced.
âšī¸ This will check whether the current fiber has been canceled before starting the computation of thunk ()
. This allows the suspension to be forced by another fiber. However, if the fiber is canceled and the cancelation exception is raised after the computation has been started, the suspension will then store the cancelation exception.
map fn susp
is equivalent to from_fun (fun () -> fn (force susp))
.