package fuseau
-
fuseau.unix
Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
Fiber-local storage.
This storage is associated to the current fiber, just like thread-local storage is associated with the current thread.
val new_key : init:(unit -> 'a) -> unit -> 'a key
new_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 FLS.key = FLS.new_key ~init:(fun () -> make_foo ()) ()
(* … *)
(* use it: *)
let _ = FLS.get k_foo
val get : 'a key -> 'a
Get the value for this key in the current fiber. Only call from inside a fiber
val set : 'a key -> 'a -> unit
Set the value for this key in the current fiber. Only call from inside a fiber
val with_value : 'a key -> 'a -> (unit -> 'b) -> 'b
with_value k v f
runs f()
in a context where key k
maps to value v
. Once f()
returns, the previous binding of k
is restored.