Module Limiter_async.Token_bucket
val sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t
type _ u
= t
val create_exn : burst_size:int -> sustained_rate_per_sec:float -> continue_on_error:bool -> ?in_flight_limit:int -> ?initial_burst_size:int -> unit -> t
val enqueue_exn : t -> ?allow_immediate_run:bool -> int -> ('a -> unit) -> 'a -> unit
enqueue_exn t x f a
enqueues an immediate job consumingx
tokens, runningf
on inputa
.if
allow_immediate_run
is true thenf
is allowed to run within the same async job asenqueue_exn
iff there are enough tokens available to fully run the job and there are no other previously enqueued jobs that have not run. If this is the case, it is run beforeenqueue_exn
returns. Otherwise no part off
is run beforeenqueue_exn
returns.If there is a failure associated with this job then the exception will be raised to the monitor in scope when
enqueue_exn
is called. Note that it may fail for a number of reasons, includingf
throws an exception, the limiter is killed, or the number of tokens requested is larger than the burst size.
val enqueue' : t -> int -> ('a -> 'b Async_kernel.Deferred.t) -> 'a -> 'b Outcome.t Async_kernel.Deferred.t
enqueue' t x f a
enqueues a deferred job consumingx
tokens, runningf
on inputa
. No part of f is run beforeenqueue'
returns.
include Common with type 'a t := 'a u
val kill : _ t -> unit
kills
t
, which aborts all enqueued jobs that haven't started and all jobs enqueued in the future. Ift
has already been killed, then callingkill t
has no effect. Note that kill does not affect currently running jobs in any way.
val is_dead : _ t -> bool
is_dead t
returnstrue
ift
was killed, either bykill
or by an unhandled exception in a job.