package opentelemetry-client

  1. Overview
  2. Docs
Client SDK for https://opentelemetry.io

Install

dune-project
 Dependency

Authors

Maintainers

Sources

opentelemetry-0.92.tbz
sha256=b635c486d1333cbb7276cc0075d5e01b017d4b37bd5941377ee1be07dfa25a45
sha512=2a19bf4e371ed2751e018c734ead2fd130d378ef0e018cda7b4aa3048af3e0db771fbd78d936199b34164950454bce0f3cb6211455e3647f7b7a85f4649bb22c

doc/src/opentelemetry-client.lwt/notifier_lwt.ml.html

Source file notifier_lwt.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(** Notification that can be used on the consumer side of a bounded queue *)

module IO = Io_lwt

type t = {
  notified: bool Atomic.t;
  cond: unit Lwt_condition.t;
  notification: Types_.notification;
  lwt_tid: int;  (** thread ID where lwt runs *)
  deleted: bool Atomic.t;
}

let create () : t =
  let notified = Atomic.make false in
  let cond = Lwt_condition.create () in
  let notification =
    Lwt_unix.make_notification (fun () ->
        Atomic.set notified false;
        Lwt_condition.broadcast cond ())
  in
  let lwt_tid = Thread.id @@ Thread.self () in
  { notified; notification; cond; lwt_tid; deleted = Atomic.make false }

let delete self : unit =
  if not (Atomic.exchange self.deleted true) then
    Lwt_unix.stop_notification self.notification

let trigger (self : t) : unit =
  let tid = Thread.id @@ Thread.self () in

  if tid = self.lwt_tid then
    (* in lwt thread, directly use the condition *)
    Lwt_condition.broadcast self.cond ()
  else if not (Atomic.exchange self.notified true) then
    Lwt_unix.send_notification self.notification

let wait (self : t) ~should_keep_waiting : unit Lwt.t =
  let open Lwt.Syntax in
  let rec loop () =
    if should_keep_waiting () then
      let* () = Lwt_condition.wait self.cond in
      loop ()
    else
      Lwt.return_unit
  in
  loop ()

let register_bounded_queue (self : t) (q : _ Bounded_queue.Recv.t) : unit =
  Bounded_queue.Recv.on_non_empty q (fun () -> trigger self)