Module Async_kernel__.Throttle
module Deferred := Async_kernel__.Deferred1
module T2 : sig ... endWe use a phantom type to distinguish between throttles, which have
max_concurrent_jobs >= 1, and sequencers, which havemax_concurrent_jobs = 1. All operations are available on both. We make the distinction because it is sometimes useful to know from the type of a throttle that it is a sequencer and that at most one job can be running at a time.
type 'a t= ('a, [ `throttle ]) T2.t
val sexp_of_t : ('a -> Ppx_sexp_conv_lib.Sexp.t) -> 'a t -> Ppx_sexp_conv_lib.Sexp.t
include Core_kernel.Invariant.S1 with type 'a t := 'a t
val invariant : 'a Base__.Invariant_intf.inv -> 'a t Base__.Invariant_intf.inv
val create : continue_on_error:bool -> max_concurrent_jobs:int -> unit tcreate ~continue_on_error ~max_concurrent_jobsreturns a throttle that will run up tomax_concurrent_jobsconcurrently. If some job raises an exception, then the throttle will be killed, unlesscontinue_on_erroris true.
val create_with : continue_on_error:bool -> 'a list -> 'a tcreate_with ~continue_on_error job_resourcesreturns a throttle that will run up toList.length job_resourcesconcurrently, and will ensure that all running jobs are supplied distinct elements ofjob_resources.
val sexp_of_outcome : ('a -> Ppx_sexp_conv_lib.Sexp.t) -> 'a outcome -> Ppx_sexp_conv_lib.Sexp.t
val enqueue' : ('a, _) T2.t -> ('a -> 'b Deferred.t) -> 'b outcome Deferred.tenqueue t jobschedulesjobto be run as soon as possible. Jobs are guaranteed to be started in the order they areenqueued and to not be started during the call toenqueue. Iftis dead, thenjobwill be immediately aborted (forenqueue, this will send an exception to the monitor in effect).
val enqueue : ('a, _) T2.t -> ('a -> 'b Deferred.t) -> 'b Deferred.tval enqueue_exclusive : ('a, _) T2.t -> (unit -> 'b Deferred.t) -> 'b Deferred.tenqueue_exclusiveschedules a job that occupies all slots of the throttle, so it won't run concurrently with any other job. The job counts as being enqueued normally, so it runs after the jobs enqueued previously and before the jobs enqueued later.enqueue_exclusivetakes O(max_concurrent_jobs) time, so you should not use it whenmax_concurrent_jobs = Int.max_value.
val monad_sequence_how : ?how:Async_kernel.Monad_sequence.how -> f:('a -> 'b Deferred.t) -> ('a -> 'b Deferred.t) Core_kernel.Staged.tmonad_sequence_how ~how ~freturns a function that behaves likef, except that it uses a throttle to limit the number of concurrent invocations that can be running simultaneously. The throttle hascontinue_on_error = false.
val monad_sequence_how2 : ?how:Async_kernel.Monad_sequence.how -> f:('a1 -> 'a2 -> 'b Deferred.t) -> ('a1 -> 'a2 -> 'b Deferred.t) Core_kernel.Staged.tval prior_jobs_done : (_, _) T2.t -> unit Deferred.tprior_jobs_done tbecomes determined when all of the jobs that were previously enqueued inthave completed.
val max_concurrent_jobs : (_, _) T2.t -> intmax_concurrent_jobs treturns the maximum number of jobs thattwill run concurrently.
val num_jobs_running : (_, _) T2.t -> intnum_jobs_running treturns the number of jobs thattis currently running. It is guaranteed that ifnum_jobs_running t < max_concurrent_jobs tthennum_jobs_waiting_to_start t = 0. That is, the throttle always uses its maximum concurrency if possible.
val num_jobs_waiting_to_start : (_, _) T2.t -> intnum_jobs_waiting_to_start treturns the number of jobs that have beenenqueued but have not yet started.
val capacity_available : (_, _) T2.t -> unit Deferred.tcapacity_available tbecomes determined the next time thatthas fewer thanmax_concurrent_jobs trunning, and hence anenqueued job would start immediately.
val kill : (_, _) T2.t -> unitkill tkillst, which aborts all enqueued jobs that haven't started and all jobs enqueued in the future.killalso initiates theat_killclean functions.If
thas already been killed, then callingkill thas no effect.
val is_dead : (_, _) T2.t -> boolis_dead treturnstrueiftwas killed, either bykillor by an unhandled exception in a job.
val at_kill : ('a, _) T2.t -> ('a -> unit Deferred.t) -> unitat_kill t cleanrunscleanon each resource whentis killed, either bykillor by an unhandled exception.cleanis called on each resource as it becomes available, i.e., immediately if the resource isn't currently in use, otherwise when the job currently using the resource finishes. If a call tocleanfails, the exception is raised to the monitor in effect whenat_killwas called.
val cleaned : (_, _) T2.t -> unit Deferred.tcleaned tbecomes determined aftertis killed, all its running jobs have completed, and allat_killclean functions have completed.
module Sequencer : sig ... endA sequencer is a throttle that is specialized to only allow one job at a time and to, by default, not continue on error.
module Deferred = Deferred