moonpool/src/ambient-context/moonpool_ambient_context.ml
Simon Cruanes d681231d9d add support for ambient-context
optional library to provide ambient-context implem using
Moonpool.Task_local_storage
2026-04-07 21:42:52 -04:00

21 lines
542 B
OCaml

open struct
module TLS = Moonpool.Task_local_storage
end
let storage : Ambient_context.Storage.t =
{
name = "moonpool";
get_context = TLS.get_local_hmap;
with_context =
(fun new_hmap f ->
let old = TLS.get_local_hmap () in
TLS.set_local_hmap new_hmap;
match f () with
| x ->
TLS.set_local_hmap old;
x
| exception exn ->
let bt = Printexc.get_raw_backtrace () in
TLS.set_local_hmap old;
Printexc.raise_with_backtrace exn bt);
}