feat: for exponential backoff

This commit is contained in:
Simon Cruanes 2025-12-05 22:00:17 -05:00
parent f519f2f49f
commit 64c7125838
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 25 additions and 0 deletions

View file

@ -0,0 +1,13 @@
type t = {
mutable delay_s: float;
min_delay_s: float;
max_delay_s: float;
}
let create () = { delay_s = 0.001; min_delay_s = 0.001; max_delay_s = 20. }
let on_success self = self.delay_s <- max self.min_delay_s (self.delay_s /. 10.)
let on_error self = self.delay_s <- min self.max_delay_s (self.delay_s *. 2.)
let[@inline] cur_duration_s self = self.delay_s

View file

@ -0,0 +1,12 @@
(** Backoff behavior in case of errors *)
type t
(** Backoff state. Not thread safe *)
val create : unit -> t
val on_success : t -> unit
val on_error : t -> unit
val cur_duration_s : t -> float