Module Async_kernel__.Clock_ns
module type Clock = Async_kernel__.Clock_intf.Clock
module type Clock_deprecated = Async_kernel__.Clock_intf.Clock_deprecated
include Clock with module Clock.Time := Async_kernel__.Import.Time_ns
module Time : sig ... end
val run_at : Time.t -> ('a -> unit) -> 'a -> unit
run_at time f a
runsf a
as soon as possible aftertime
. Iftime
is in the past, thenrun_at
will immediately schedule a jobt
that will runf a
. In no situation willrun_at
actually callf
itself. The call tof
will always be in another job.
val run_after : Time.Span.t -> ('a -> unit) -> 'a -> unit
run_after
is likerun_at
, except that one specifies a time span rather than an absolute time.
val at : Time.t -> unit Async_kernel__.Clock_intf.Deferred.t
at time
returns a deferredd
that will become determined as soon as possible aftertime
val after : Time.Span.t -> unit Async_kernel__.Clock_intf.Deferred.t
after
is likeat
, except that one specifies a time span rather than an absolute time. If you set up a lot ofafter
events at the beginning of your program they will trigger at the same time. UseTime.Span.randomize
to 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.t
with_timeout span d
returns a deferred that will become determined after eitherspan
elapses ord
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
andrun_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__.Clock_intf.Deferred.t -> (unit -> Time.Span.t) -> unit Async_kernel__.Async_stream.t
at_varying_intervals f ?stop
returns 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 afterstop
becomes determined.
val at_intervals : ?start:Time.t -> ?stop:unit Async_kernel__.Clock_intf.Deferred.t -> Time.Span.t -> unit Async_kernel__.Async_stream.t
at_intervals interval ?start ?stop
returns a stream whose elements will become determined at nonnegative integer multiples ofinterval
after thestart
time, untilstop
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, orstart
is not provided, then there will be no element before theinterval
has passed.If the interval is too small or the CPU is too loaded,
at_intervals
will skip until the next upcoming multiple ofinterval
afterstart
.
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) -> unit
every' ?start ?stop span f
runsf ()
everyspan
amount of time starting whenstart
becomes determined and stopping whenstop
becomes determined.every'
waits until the result off ()
becomes determined before waiting for the nextspan
.It is guaranteed that if
stop
becomes determined, even during evaluation off
, thenf
will not be called again by a subsequent iteration of the loop.It is an error for
span
to be nonpositive.With
~continue_on_error:true
, whenf
asynchronously raises, iteration continues. With~continue_on_error:false
, iff
asynchronously raises, then iteration only continues when the result off
becomes determined.Exceptions raised by
f
are always sent to monitor in effect whenevery'
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 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) -> unit
every ?start ?stop span f
isevery' ?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) -> unit
run_at_intervals' ?start ?stop span f
runsf()
at increments ofstart + i * span
for nonnegative integersi
, untilstop
becomes determined. If the result off
is not determined fast enough then the next interval(s) are skipped so that there are never multiple concurrent invocations off
in flight.Exceptions raised by
f
are 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) -> 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 ())