Moonpool.Task_local_storageTask-local storage.
This storage is associated to the current task, just like thread-local storage is associated with the current thread. The storage is carried along in case the current task is suspended.
Underlying storage for a task. This is mutable and not thread-safe.
val dummy : tval new_key : init:(unit -> 'a) -> unit -> 'a keynew_key ~init () makes a new key. Keys are expensive and should never be allocated dynamically or in a loop. The correct pattern is, at toplevel:
let k_foo : foo Task_ocal_storage.key =
Task_local_storage.new_key ~init:(fun () -> make_foo ()) ()
(* … *)
(* use it: *)
let … = Task_local_storage.get k_fooval get : 'a key -> 'aget k gets the value for the current task for key k. Must be run from inside a task running on a runner.
val get_opt : 'a key -> 'a optionget_opt k gets the current task's value for key k, or None if not run from inside the task.
val set : 'a key -> 'a -> unitset k v sets the storage for k to v. Must be run from inside a task running on a runner.
val with_value : 'a key -> 'a -> (unit -> 'b) -> 'bwith_value k v f sets k to v for the duration of the call to f(). When f() returns (or fails), k is restored to its old value.
val get_current : unit -> t optionAccess the current storage, or None if not run from within a task.
module Direct : sig ... endDirect access to values from a storage handle