fixes and cleanup in cohttp-eio client

This commit is contained in:
Simon Cruanes 2025-12-17 13:59:58 -05:00
parent 05ad0421db
commit 3c08842e2d
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 15 additions and 13 deletions

View file

@ -1,5 +1,3 @@
open Eio.Std
(*
https://github.com/open-telemetry/oteps/blob/main/text/0035-opentelemetry-protocol.md
https://github.com/open-telemetry/oteps/blob/main/text/0099-otlp-http.md
@ -48,7 +46,9 @@ struct
ensure it runs in the Eio thread? *)
Eio.Condition.broadcast self.cond
let delete = ignore
let delete self =
trigger self;
()
let wait self =
Eio.Mutex.lock self.mutex;
@ -193,12 +193,10 @@ let remove_exporter () =
let remove_backend = remove_exporter
let with_setup ?config ?(enable = true) f env =
if enable then
let with_setup ?config ?(enable = true) env f =
if enable then (
Eio.Switch.run @@ fun sw ->
snd
@@ Fiber.pair
(fun () -> setup_ ~sw ?config env)
(fun () -> Fun.protect ~finally:(fun () -> remove_backend ()) f)
else
setup_ ~sw ?config env;
Fun.protect f ~finally:remove_exporter
) else
f ()

View file

@ -49,11 +49,15 @@ val setup :
an atomic boolean. When it becomes true, background threads will all stop
after a little while. *)
val remove_backend : unit -> unit
(** Shutdown current backend
val remove_exporter : unit -> unit
(** Shutdown current exporter
@since 0.12 *)
val remove_backend : unit -> unit
[@@deprecated "use remove_exporter"]
(** @since 0.12 *)
val with_setup :
?config:Config.t -> ?enable:bool -> (unit -> 'a) -> Eio_unix.Stdenv.base -> 'a
?config:Config.t -> ?enable:bool -> Eio_unix.Stdenv.base -> (unit -> 'a) -> 'a
(** [with_setup () f] is like [setup(); f()] but takes care of cleaning up after
[f()] returns See {!setup} for more details. *)