details on Interval_limiter

This commit is contained in:
Simon Cruanes 2026-01-12 20:34:40 -05:00
parent 008ae6ddfd
commit 3ba0523227
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 5 additions and 1 deletions

View file

@ -3,6 +3,8 @@ type t = {
last: Mtime.t Atomic.t;
}
let[@inline] min_interval self = self.min_interval
let create ~min_interval () : t =
{ 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
if Mtime.Span.compare elapsed self.min_interval >= 0 then
(* 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
else
false

View file

@ -5,6 +5,8 @@ type t
val create : min_interval:Mtime.span -> unit -> t
val min_interval : t -> Mtime.span
val make_attempt : t -> bool
(** [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