package async_kernel
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=55a32c8b8e6aaaecb8357644515884367ec99b703fe8f984212b714a0e554c65
md5=d12b61a3f95325a511c50964bc9c819e
doc/async_kernel.limiter_async/Limiter_async/Token_bucket/index.html
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 consuming x
tokens, running f
on input a
.
if allow_immediate_run
is true then f
is allowed to run within the same async job as enqueue_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 before enqueue_exn
returns. Otherwise no part of f
is run before enqueue_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, including f
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 consuming x
tokens, running f
on input a
. No part of f is run before enqueue'
returns.
include Common with type 'a t := 'a u
val kill : _ u -> unit
kills t
, which aborts all enqueued jobs that haven't started and all jobs enqueued in the future. If t
has already been killed, then calling kill t
has no effect. Note that kill does not affect currently running jobs in any way.
val is_dead : _ u -> bool
is_dead t
returns true
if t
was killed, either by kill
or by an unhandled exception in a job.