File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,32 @@ let remove_document store uri =
2727 let + () = Document. close doc in
2828 Table. remove store uri)
2929
30- let get_size store = Table. length store
30+ let unregister_promotions t uris =
31+ let * () = Fiber. return () in
32+ List. filter uris ~f: (fun uri ->
33+ match Table. find t.db uri with
34+ | None -> false
35+ | Some doc ->
36+ let doc = { doc with promotions = doc.promotions - 1 } in
37+ let unsubscribe = doc.promotions = 0 in
38+ if unsubscribe && doc.document = None then
39+ Table. remove t.db uri
40+ else
41+ Table. set t.db uri doc;
42+ unsubscribe)
43+ |> unregister_request t
44+
45+ let register_promotions t uris =
46+ let * () = Fiber. return () in
47+ List. filter uris ~f: (fun uri ->
48+ let doc, subscribe =
49+ match Table. find t.db uri with
50+ | None -> ({ document = None ; promotions = 0 }, true )
51+ | Some doc -> ({ doc with promotions = doc.promotions + 1 }, false )
52+ in
53+ Table. set t.db uri doc;
54+ subscribe)
55+ |> register_request t
3156
3257let close t =
3358 Fiber. of_thunk (fun () ->
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ val get_opt : t -> Uri.t -> Document.t option
1212
1313val remove_document : t -> Uri .t -> unit Fiber .t
1414
15- val get_size : t -> int
15+ val unregister_promotions : t -> Uri .t list -> unit Fiber .t
16+
17+ val register_promotions : t -> Uri .t list -> unit Fiber .t
1618
1719val close : t -> unit Fiber .t
You can’t perform that action at this time.
0 commit comments