mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-07 18:37:56 -05:00
details on Interval_limiter
This commit is contained in:
parent
008ae6ddfd
commit
3ba0523227
2 changed files with 5 additions and 1 deletions
|
|
@ -3,6 +3,8 @@ type t = {
|
||||||
last: Mtime.t Atomic.t;
|
last: Mtime.t Atomic.t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let[@inline] min_interval self = self.min_interval
|
||||||
|
|
||||||
let create ~min_interval () : t =
|
let create ~min_interval () : t =
|
||||||
{ min_interval; last = Atomic.make Mtime.min_stamp }
|
{ min_interval; last = Atomic.make Mtime.min_stamp }
|
||||||
|
|
||||||
|
|
@ -12,7 +14,7 @@ let make_attempt (self : t) : bool =
|
||||||
let elapsed = Mtime.span last now in
|
let elapsed = Mtime.span last now in
|
||||||
if Mtime.Span.compare elapsed self.min_interval >= 0 then
|
if Mtime.Span.compare elapsed self.min_interval >= 0 then
|
||||||
(* attempts succeeds, unless another thread updated [self.last]
|
(* attempts succeeds, unless another thread updated [self.last]
|
||||||
in the mean time *)
|
in the mean time, so we return [true] iff the CAS was successful *)
|
||||||
Atomic.compare_and_set self.last last now
|
Atomic.compare_and_set self.last last now
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ type t
|
||||||
|
|
||||||
val create : min_interval:Mtime.span -> unit -> t
|
val create : min_interval:Mtime.span -> unit -> t
|
||||||
|
|
||||||
|
val min_interval : t -> Mtime.span
|
||||||
|
|
||||||
val make_attempt : t -> bool
|
val make_attempt : t -> bool
|
||||||
(** [make_attempt lim] returns [true] if the last successful attempt was more
|
(** [make_attempt lim] returns [true] if the last successful attempt was more
|
||||||
than [min_interval] ago, as measured by mtime. If so, this counts as the new
|
than [min_interval] ago, as measured by mtime. If so, this counts as the new
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue