mirror of
https://github.com/c-cube/moonpool.git
synced 2026-05-05 08:54:24 -04:00
add support for ambient-context
optional library to provide ambient-context implem using Moonpool.Task_local_storage
This commit is contained in:
parent
471feb96d6
commit
d681231d9d
5 changed files with 29 additions and 1 deletions
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
|
|
@ -27,7 +27,7 @@ jobs:
|
|||
- run: opam exec -- dune build @install
|
||||
|
||||
# install some depopts
|
||||
- run: opam install thread-local-storage trace hmap
|
||||
- run: opam install thread-local-storage trace hmap ambient-context.0.2
|
||||
- run: opam exec -- dune build --profile=release --force @install @runtest
|
||||
|
||||
compat:
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@
|
|||
:with-test)))
|
||||
(depopts
|
||||
hmap
|
||||
(ambient-context (>= 0.2))
|
||||
(trace
|
||||
(>= 0.6)))
|
||||
(tags
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ depends: [
|
|||
]
|
||||
depopts: [
|
||||
"hmap"
|
||||
"ambient-context" {>= "0.2"}
|
||||
"trace" {>= "0.6"}
|
||||
]
|
||||
build: [
|
||||
|
|
|
|||
5
src/ambient-context/dune
Normal file
5
src/ambient-context/dune
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(library
|
||||
(name moonpool_ambient_context)
|
||||
(public_name moonpool.ambient-context)
|
||||
(optional) ; ambient-context
|
||||
(libraries moonpool hmap ambient-context))
|
||||
21
src/ambient-context/moonpool_ambient_context.ml
Normal file
21
src/ambient-context/moonpool_ambient_context.ml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
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);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue