Source file ambient_context_lwt.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(** Storage using Lwt keys *)

open Ambient_context_core

open struct
  let lwt_context_key : Context.t Lwt.key = Lwt.new_key ()
end

let storage : Storage.t =
  {
    name = "lwt";
    get_context =
      (fun () -> Lwt.get lwt_context_key |> Option.value ~default:Hmap.empty);
    with_context = (fun ctx f -> Lwt.with_value lwt_context_key (Some ctx) f);
  }