Module Async_unix.Clock
A Clock based on Core.Time.
include Async_kernel.Clock_ns.Clock with module Time := Core.Time
module Time : sig ... endval run_at : Time.t -> ('a -> unit) -> 'a -> unitrun_at time f arunsf aas soon as possible aftertime. Iftimeis in the past, thenrun_atwill immediately schedule a jobtthat will runf a. In no situation willrun_atactually callfitself. The call tofwill always be in another job.
val run_after : Time.Span.t -> ('a -> unit) -> 'a -> unitrun_afteris likerun_at, except that one specifies a time span rather than an absolute time.
val at : Time.t -> unit Async_kernel__.Clock_intf.Deferred.tat timereturns a deferreddthat will become determined as soon as possible aftertime
val after : Time.Span.t -> unit Async_kernel__.Clock_intf.Deferred.tafteris likeat, except that one specifies a time span rather than an absolute time. If you set up a lot ofafterevents at the beginning of your program they will trigger at the same time. UseTime.Span.randomizeto even them out.
val with_timeout : Time.Span.t -> 'a Async_kernel__.Clock_intf.Deferred.t -> [ `Timeout | `Result of 'a ] Async_kernel__.Clock_intf.Deferred.twith_timeout span dreturns a deferred that will become determined after eitherspanelapses ordis determined, returning either`Timeoutor`Resultdepending on which one succeeded first. At the time the returned deferred becomes determined, both things may have happened, in which case`Resultis given preference.
module Event : sig ... endEvents provide variants of
run_atandrun_afterwith 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__.Clock_intf.Deferred.t -> (unit -> Time.Span.t) -> unit Async_kernel__.Async_stream.tat_varying_intervals f ?stopreturns a stream whose next element becomes determined by callingf ()and waiting for that amount of time, and then looping to determine subsequent elements. The stream will end afterstopbecomes determined.
val at_intervals : ?start:Time.t -> ?stop:unit Async_kernel__.Clock_intf.Deferred.t -> Time.Span.t -> unit Async_kernel__.Async_stream.tat_intervals interval ?start ?stopreturns a stream whose elements will become determined at nonnegative integer multiples ofintervalafter thestarttime, untilstopbecomes 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
startis not in the future, orstartis not provided, then there will be no element before theintervalhas passed.If the interval is too small or the CPU is too loaded,
at_intervalswill skip until the next upcoming multiple ofintervalafterstart.
val every' : ?start:unit Async_kernel__.Clock_intf.Deferred.t -> ?stop:unit Async_kernel__.Clock_intf.Deferred.t -> ?continue_on_error:bool -> ?finished:unit Async_kernel.Ivar.t -> Time.Span.t -> (unit -> unit Async_kernel__.Clock_intf.Deferred.t) -> unitevery' ?start ?stop span frunsf ()everyspanamount of time starting whenstartbecomes determined and stopping whenstopbecomes determined.every'waits until the result off ()becomes determined before waiting for the nextspan.It is guaranteed that if
stopbecomes determined, even during evaluation off, thenfwill not be called again by a subsequent iteration of the loop.It is an error for
spanto be nonpositive.With
~continue_on_error:true, whenfasynchronously raises, iteration continues. With~continue_on_error:false, iffasynchronously raises, then iteration only continues when the result offbecomes determined.Exceptions raised by
fare always sent to monitor in effect whenevery'was called, even with~continue_on_error:true.If
finishedis supplied,every'will fill it once all of the following become determined:start,stop, and the result of the final call tof.
val every : ?start:unit Async_kernel__.Clock_intf.Deferred.t -> ?stop:unit Async_kernel__.Clock_intf.Deferred.t -> ?continue_on_error:bool -> Time.Span.t -> (unit -> unit) -> unitevery ?start ?stop span fisevery' ?start ?stop span (fun () -> f (); return ()).
val run_at_intervals' : ?start:Time.t -> ?stop:unit Async_kernel__.Clock_intf.Deferred.t -> ?continue_on_error:bool -> Time.Span.t -> (unit -> unit Async_kernel__.Clock_intf.Deferred.t) -> unitrun_at_intervals' ?start ?stop span frunsf()at increments ofstart + i * spanfor nonnegative integersi, untilstopbecomes determined. If the result offis not determined fast enough then the next interval(s) are skipped so that there are never multiple concurrent invocations offin flight.Exceptions raised by
fare always sent to monitor in effect whenrun_at_intervals'was called, even with~continue_on_error:true.
val run_at_intervals : ?start:Time.t -> ?stop:unit Async_kernel__.Clock_intf.Deferred.t -> ?continue_on_error:bool -> Time.Span.t -> (unit -> unit) -> unitrun_at_intervals ?start ?stop ?continue_on_error span fis equivalent to:run_at_intervals' ?start ?stop ?continue_on_error span (fun () -> f (); return ())