Up

module Clock

: sig

Schedule jobs to run at a time in the future.

The underlying implementation uses a heap of events, one for each job that needs to run in the future. The Async scheduler is responsible for waking up at the right time to run the jobs.

#
val run_at : Core.Std.Time.t -> ('a -> unit) -> 'a -> unit

run_at time f a runs f a as soon as possible after time. If time is in the past, then run_at will immediately schedule a job t that will run f a. In no situation will run_at actually call f itself. The call to f will always be in another job.

run_after is like run_at, except that one specifies a time span rather than an absolute time.

#
val run_after : Core.Std.Time.Span.t -> ('a -> unit) -> 'a -> unit
#
val at : Core.Std.Time.t -> unit Deferred.t

at time returns a deferred d that will become determined as soon as possible after time

after is like at, except that one specifies a time span rather than an absolute time.

If you set up a lot of after events at the beginning of your program they will trigger at the same time. Use Time.Span.randomize to even that out.

#
val after : Core.Std.Time.Span.t -> unit Deferred.t
#
val with_timeout : Core.Std.Time.Span.t -> 'a Deferred.t -> [
| `Timeout
| `Result of 'a
] Deferred.t

with_timeout span d does pretty much what one would expect. Note that at the point of checking if d is determined and the timeout has expired, the resulting deferred will be determined with `Result. In other words, since there is an inherent race between d and the timeout, preference is given to d.

#
module Event : sig

Events provide abortable versions of at and after.

#
type t
include Core.Std.Invariant.S with type t := t
#
val status : t -> [
| `Happened
| `Will_happen_at of Core.Std.Time.t
| `Aborted
]

If status returns `Will_happen_at time, it is possible that time < Time.now (), if Async's scheduler hasn't yet gotten the chance to update its clock, e.g. due to user jobs running.

#
val abort : t -> [
| `Ok
| `Previously_aborted
| `Previously_happened
]
#
val at : Core.Std.Time.t -> t * [
| `Happened
| `Aborted
] Deferred.t
#
val after : Core.Std.Time.Span.t -> t * [
| `Happened
| `Aborted
] Deferred.t
#
val sexp_of_t : t -> Sexplib.Sexp.t
end
#
val at_varying_intervals : ?stop:unit Deferred.t -> (unit -> Core.Std.Time.Span.t) -> unit Async_stream.t

at_varying_intervals f ?stop returns a stream whose next element becomes determined by calling f () and waiting for that amount of time, and then looping to determine subsequent elements. The stream will end after stop becomes determined.

#
val at_intervals : ?start:Core.Std.Time.t -> ?stop:unit Deferred.t -> Core.Std.Time.Span.t -> unit Async_stream.t

at_intervals interval ?start ?stop returns a stream whose elements will become determined at nonnegative integer multiples of interval after the start time, until stop becomes determined:

       start + 0 * interval
       start + 1 * interval
       start + 2 * interval
       start + 3 * interval
       ...

If the interval is too small or the CPU is too loaded, at_intervals will skip until the next upcoming multiple of interval after start.

#
val every' : ?start:unit Deferred.t -> ?stop:unit Deferred.t -> ?continue_on_error:bool -> Core.Std.Time.Span.t -> (unit -> unit Deferred.t) -> unit

every' ?start ?stop span f runs f() every span amount of time starting when start becomes determined and stopping when stop becomes determined. every waits until the result of f() becomes determined before waiting for the next span.

It is guaranteed that if stop becomes determined, even during evaluation of f, then f will not be called again by a subsequent iteration of the loop.

It is an error for span to be nonpositive.

Exceptions raised by f are always sent to monitor in effect when every' was called, even with ~continue_on_error:true.

#
val every : ?start:unit Deferred.t -> ?stop:unit Deferred.t -> ?continue_on_error:bool -> Core.Std.Time.Span.t -> (unit -> unit) -> unit

every ?start ?stop span f is every' ?start ?stop span (fun () -> f (); Deferred.unit)

#
val run_at_intervals' : ?start:Core.Std.Time.t -> ?stop:unit Deferred.t -> ?continue_on_error:bool -> Core.Std.Time.Span.t -> (unit -> unit Deferred.t) -> unit

run_at_intervals' ?start ?stop span f runs f() at increments of start + i * span for non-negative integers i, until stop becomes determined. run_at_intervals' waits for the result of f to become determined before waiting for the next interval.

Exceptions raised by f are always sent to monitor in effect when run_at_intervals' was called, even with ~continue_on_error:true.

#
val run_at_intervals : ?start:Core.Std.Time.t -> ?stop:unit Deferred.t -> ?continue_on_error:bool -> Core.Std.Time.Span.t -> (unit -> unit) -> unit

run_at_intervals ?start ?stop ?continue_on_error span f is equivalent to:

      run_at_intervals' ?start ?stop ?continue_on_error span
        (fun () -> f (); Deferred.unit)
end