package ambient-context

  1. Overview
  2. Docs
Abstraction over thread-local / continuation-local storage mechanisms for communication with transitive dependencies

Install

dune-project
 Dependency

Authors

Maintainers

Sources

ambient-context-0.2.tbz
sha256=f451f4ed467ef0c15f472cda1021a89e96afdf3a32970ea047faf057a01c72d3
sha512=3115fd7b45ac171f7a971013dd6f32ec317fc274d800a86870a0dd43574e27b404090fbc51dae5e4c8af4961d706f84abf3843a6cf8dc57f711211cd2b547780

doc/src/ambient-context.tls/ambient_context_tls.ml.html

Source file ambient_context_tls.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
open Ambient_context_core

open struct
  module TLS = Thread_local_storage

  (* key used to access the context *)
  let tls_k_context : Context.t TLS.t = TLS.create ()
end

let storage : Storage.t =
  {
    name = "tls";
    get_context =
      (fun () -> try TLS.get_exn tls_k_context with TLS.Not_set -> Hmap.empty);
    with_context =
      (fun ctx f ->
        let old =
          try TLS.get_exn tls_k_context with TLS.Not_set -> Hmap.empty
        in
        let finally () = TLS.set tls_k_context old in
        TLS.set tls_k_context ctx;
        Fun.protect ~finally f);
  }