package async_unix

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

A Clock based on Core.Time.

include Async_kernel.Clock_ns.Clock with module Time := Time_unix
module Or_timeout : sig ... end
val run_at : Time_unix.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.

val run_after : Time_unix.Span.t -> ('a -> unit) -> 'a -> unit

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

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.

with_timeout span d returns a deferred that will become determined after either span elapses or d is determined, returning either `Timeout or `Result depending on which one succeeded first. At the time the returned deferred becomes determined, both things may have happened, in which case `Result is given preference.

module Event : sig ... end

Events provide variants of run_at and run_after with the ability to abort or reschedule an event that hasn't yet happened. Once an event happens or is aborted, Async doesn't use any space for tracking it.

val at_varying_intervals : ?stop:unit Async_kernel.Deferred.t -> (unit -> Time_unix.Span.t) -> unit Async_kernel.Tail.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:Time_unix.t -> ?stop:unit Async_kernel.Deferred.t -> Time_unix.Span.t -> unit Async_kernel.Tail.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
        ...

Note that only elements that are strictly in the future ever become determined. In particular, if start is not in the future, or start is not provided, then there will be no element before the interval has passed.

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 Async_kernel.Deferred.t -> ?stop:unit Async_kernel.Deferred.t -> ?continue_on_error:bool -> ?finished:unit Async_kernel.Ivar.t -> Time_unix.Span.t -> (unit -> unit Async_kernel.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 outcome 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.

continue_on_error controls what should happen if f raises an exception. With ~continue_on_error:false, iteration only continues if f successfully returns a deferred and that deferred is determined. With ~continue_on_error:true, iteration also continues if f raises an exception. If f raises an exception asynchronously, this may cause us to proceed with the next iteration while the previous call to f is still running.

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

If finished is supplied, every' will fill it once all of the following become determined: start, stop, and the outcome of the final call to f.

val every : ?start:unit Async_kernel.Deferred.t -> ?stop:unit Async_kernel.Deferred.t -> ?continue_on_error:bool -> Time_unix.Span.t -> (unit -> unit) -> unit

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

val run_at_intervals' : ?start:Time_unix.t -> ?stop:unit Async_kernel.Deferred.t -> ?continue_on_error:bool -> Time_unix.Span.t -> (unit -> unit Async_kernel.Deferred.t) -> unit

run_at_intervals' ?start ?stop span f runs f() at increments of start + i * span for nonnegative integers i, until stop becomes determined. If the result of f is not determined fast enough then the next interval(s) are skipped so that there are never multiple concurrent invocations of f in flight.

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:Time_unix.t -> ?stop:unit Async_kernel.Deferred.t -> ?continue_on_error:bool -> Time_unix.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 (); return ()) 
val duration_of : (unit -> 'a Async_kernel.Deferred.t) -> ('a * Time_unix.Span.t) Async_kernel.Deferred.t

duration_of f invokes f () and measures how long it takes from the invocation to after the deferred is determined.

Note that the measurement is not exact; because it involves an additional map on the deferred, the timing also includes the duration of jobs in the job queue when f () is determined.

OCaml

Innovation. Community. Security.