module Throttle: Throttle
module T2:sig
..end
max_concurrent_jobs >= 1
, and sequencers, which have max_concurrent_jobs = 1
.
type'a
t =('a, [ `throttle ]) T2.t
include Invariant.S1
val create : continue_on_error:bool -> max_concurrent_jobs:int -> unit t
create ~continue_on_error ~max_concurrent_jobs
returns a throttle that will run up
to max_concurrent_jobs
concurrently.
If some job raises an exception, then the throttle will be killed, unless
continue_on_error
is true.
val create_with : continue_on_error:bool -> 'a list -> 'a t
create_with ~continue_on_error job_resources
returns a throttle that will run up to
List.length job_resources
concurrently, and will ensure that all running jobs are
supplied distinct elements of job_resources
.type'a
outcome =[ `Aborted | `Ok of 'a | `Raised of exn ]
val enqueue' : ('a, 'c) T2.t ->
('a -> 'b Deferred.t) -> 'b outcome Deferred.t
enqueue t job
schedules job
to be run as soon as possible. Jobs are guaranteed to
be started in the order they are enqueue
d. If t
is dead, then job
will be
immediately aborted (for enqueue
this will send an exception to the monitor in
effect).val enqueue : ('a, 'c) T2.t -> ('a -> 'b Deferred.t) -> 'b Deferred.t
val prior_jobs_done : ('a, 'b) T2.t -> unit Deferred.t
prior_jobs_done t
becomes determined when all of the jobs that were previously
enqueued in t
have completed.val max_concurrent_jobs : ('a, 'b) T2.t -> int
max_concurrent_jobs t
returns the maximum number of jobs that t
will run
concurrently.val num_jobs_running : ('a, 'b) T2.t -> int
num_jobs_running t
returns the number of jobs that t
is currently running. It
is guaranteed that if num_jobs_running t < max_concurrent_jobs t
then
num_jobs_waiting_to_start t = 0
. That is, the throttle always uses its maximum
concurrency if possible.val num_jobs_waiting_to_start : ('a, 'b) T2.t -> int
num_jobs_waiting_to_start t
returns the number of jobs that have been enqueue
d but
have not yet started.val capacity_available : ('a, 'b) T2.t -> unit Deferred.t
capacity_available t
becomes determined the next time that t
has fewer than
max_concurrent_jobs t
running, and hence an enqueue
d job would start
immediately.val kill : 'a t -> unit
kill t
kills t
, which aborts all enqeued jobs that haven't started and all jobs
enqueued in the future. kill
also initiates the at_kill
clean functions.
If t
has already been killed, then calling kill t
has no effect.
val is_dead : 'a t -> bool
is_dead t
returns true
if t
was killed, either by kill
or by an unhandled
exception in a job.val at_kill : 'a t -> ('a -> unit Deferred.t) -> unit
at_kill t clean
runs clean
on each resource when t
is killed, either by kill
or an unhandled exception. clean
is 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 to clean
fails, the exception
is raised to the monitor in effect when at_kill
was called.val cleaned : 'a t -> unit Deferred.t
cleaned t
becomes determined after t
is killed and all of its at_kill
clean
functions have completed.module Sequencer:sig
..end
val sexp_of_t : ('a -> Sexplib.Sexp.t) -> 'a t -> Sexplib.Sexp.t
create ~continue_on_error ~max_concurrent_jobs
returns a throttle that will run up
to max_concurrent_jobs
concurrently.
If some job raises an exception, then the throttle will be killed, unless
continue_on_error
is true.
create_with ~continue_on_error job_resources
returns a throttle that will run up to
List.length job_resources
concurrently, and will ensure that all running jobs are
supplied distinct elements of job_resources
.
val sexp_of_outcome : ('a -> Sexplib.Sexp.t) -> 'a outcome -> Sexplib.Sexp.t
enqueue t job
schedules job
to be run as soon as possible. Jobs are guaranteed to
be started in the order they are enqueue
d. If t
is dead, then job
will be
immediately aborted (for enqueue
this will send an exception to the monitor in
effect).prior_jobs_done t
becomes determined when all of the jobs that were previously
enqueued in t
have completed.max_concurrent_jobs t
returns the maximum number of jobs that t
will run
concurrently.num_jobs_running t
returns the number of jobs that t
is currently running. It
is guaranteed that if num_jobs_running t < max_concurrent_jobs t
then
num_jobs_waiting_to_start t = 0
. That is, the throttle always uses its maximum
concurrency if possible.num_jobs_waiting_to_start t
returns the number of jobs that have been enqueue
d but
have not yet started.capacity_available t
becomes determined the next time that t
has fewer than
max_concurrent_jobs t
running, and hence an enqueue
d job would start
immediately.kill t
kills t
, which aborts all enqeued jobs that haven't started and all jobs
enqueued in the future. kill
also initiates the at_kill
clean functions.
If t
has already been killed, then calling kill t
has no effect.
is_dead t
returns true
if t
was killed, either by kill
or by an unhandled
exception in a job.
at_kill t clean
runs clean
on each resource when t
is killed, either by kill
or an unhandled exception. clean
is 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 to clean
fails, the exception
is raised to the monitor in effect when at_kill
was called.
cleaned t
becomes determined after t
is killed and all of its at_kill
clean
functions have completed.
A sequencer is a throttle that is specialized to only allow one job at a time and to,
by default, not continue on error.
default is false