Module Throttle

module Throttle: sig .. end
Throttles for simultaneous computations.

A throttle schedules asynchronous jobs so that at any given point in time no more than max_concurrent_jobs jobs are running. A job f is considered to be running from the time f () is executed until the deferred returned by f () becomes determined, or f () throws an exception.

A throttle becomes "dead" if one of its jobs throws an exception, and the throttle is not set to continue on error.

A throttle is essentially a pipe to which one can feed jobs.


type t 
val invariant : t -> unit
val create : continue_on_error:bool -> max_concurrent_jobs:int -> t
create ~continue_on_error ~max_concurrent_jobs returns a throttle that will runs up to max_concurrent_jobs concurrently.

If some job raises an exception, then the throttle will stop, unless continue_on_error is true.

type 'a outcome = [ `Aborted | `Ok of 'a | `Raised of exn ] 
module Job: sig .. end
val enqueue_job : t -> 'a Job.t -> unit
val enqueue' : t -> (unit -> 'a Deferred.t) -> 'a outcome Deferred.t
enqueue t ~monitor job schedules job to be run as soon as possible. Jobs are guaranteed to be started in the order they are enqueued.

enqueue raises an exception if the throttle is dead.

val enqueue : t -> (unit -> 'a Deferred.t) -> 'a Deferred.t
val prior_jobs_done : t -> unit Deferred.t
val num_jobs_waiting_to_start : t -> int
module Sequencer: sig .. end
A sequencer is a throttle that is:
val sexp_of_t : t -> Sexplib.Sexp.t
val ounit_tests : unit -> OUnit.test

create ~continue_on_error ~max_concurrent_jobs returns a throttle that will runs up to max_concurrent_jobs concurrently.

If some job raises an exception, then the throttle will stop, unless continue_on_error is true.

enqueue t ~monitor job schedules job to be run as soon as possible. Jobs are guaranteed to be started in the order they are enqueued.

enqueue raises an exception if the throttle is dead.

A sequencer is a throttle that is:

1. specialized to only allow one job at a time and to not continue on error, and 2. generalized to carry its own state, and enforce mutually exclusive access to that state by the jobs

create a new monitor with the specified initial state

schedule a state-accessing operation