Module Async_kernel.Synchronous_time_source
A synchronous version of Async_kernel.Time_source. advance_by_alarms runs alarms immediately, rather than enqueueing Async jobs.
Synchronous_time_source is a wrapper around Timing_wheel_ns. One difference is that Synchronous_time_source alarms fire in non-decreasing time order, whereas in Timing_wheel_ns that is only true for alarms in different time intervals as determined by alarm_precision.
module T1 : sig ... endmodule Read_write : sig ... endtype t= Core_kernel.read T1.t
val sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t
val invariant_with_jobs : job:Async_kernel__.Job.t Core_kernel.Invariant.t -> t Core_kernel.Invariant.t
val read_only : [> Core_kernel.read ] T1.t -> t
val create : ?timing_wheel_config:Core_kernel.Timing_wheel_ns.Config.t -> now:Async_kernel__.Import.Time_ns.t -> unit -> Core_kernel.read_write T1.tcreate ~now ()creates a new time source. The defaulttiming_wheel_confighas 100 microsecond precision, with levels of >1s, >1m, >1h, >1d. Thetiming_wheel_configis used to tune performance; configuration does not affect the fact that alarms fire in non-decreasing time order.
val alarm_precision : [> Core_kernel.read ] T1.t -> Async_kernel__.Import.Time_ns.Span.tval is_wall_clock : [> Core_kernel.read ] T1.t -> boolis_wall_clockreports whether this time source represents 'wall clock' time, or some alternate source of time.
val now : [> Core_kernel.read ] T1.t -> Async_kernel__.Import.Time_ns.tThe behavior of
nowis special forwall_clock (); it always callsTime_ns.now (), so it can return times that the time source has not yet been advanced to.
val timing_wheel_now : [> Core_kernel.read ] T1.t -> Async_kernel__.Import.Time_ns.tRemoves the special behavior of
nowforwall_clock (); it always returns the timing wheel's notion of now, which means that the following inequality always holds:timing_wheel_now () <= now ().
val advance_by_alarms : [> Core_kernel.write ] T1.t -> to_:Async_kernel__.Import.Time_ns.t -> unit Core_kernel.Or_error.tadvance_by_alarms t ~to_advancest's time toto_, running callbacks for all alarms intwhoseat <= to_. Callbacks run in nondecreasing order ofat. Ifto_ <= now t, thennow tdoes not change (and in particular does not go backward), but alarms withat <= to_may still may fire.
val run_at : [> Core_kernel.read ] T1.t -> Async_kernel__.Import.Time_ns.t -> callback -> unitrun_at t at fschedules an alarm that will runfduring the next subsequentadvance_by_alarms t ~to_that causesnow t >= at. Ifat <= now t, thenfwill to run at the next call toadvance_by_alarms.fis allowed to do allSynchronous_time_sourceoperations except foradvance_by_alarms(becausefis already running duringadvance_by_alarms. Adding alarms is not zero-alloc and the underlying events live in the OCaml heap.
val run_after : [> Core_kernel.read ] T1.t -> Async_kernel__.Import.Time_ns.Span.t -> callback -> unitrun_after t span fisrun_at t (now t + span) f.
val run_at_intervals : [> Core_kernel.read ] T1.t -> Async_kernel__.Import.Time_ns.Span.t -> callback -> unitrun_at_intervals t span fcausesfto run at intervalsnow t + k * span, for k = 0, 1, 2, etc.run_at_intervalsraises ifspan < alarm_precision t.
val alarm_upper_bound : [> Core_kernel.read ] T1.t -> Async_kernel__.Import.Time_ns.talarm_upper_bound treturns the upper bound on aTime_ns.tthat can be supplied torun_at.alarm_upper_bound tis not constant; its value increases asnow tincreases.
val max_allowed_alarm_time : [> Core_kernel.read ] T1.t -> Async_kernel__.Import.Time_ns.tmax_allowed_alarm_time treturns the greatestatthat can be supplied toadd.max_allowed_alarm_timeis not constant; its value increases asnow tincreases.
module Event : sig ... endval default_timing_wheel_config : Core_kernel.Timing_wheel_ns.Config.tval wall_clock : unit -> tA time source with
now tgiven by wall-clock time (i.e.Time_ns.now), and automatically advanced at the start of each Async cycle. The wall clock uses the same timing wheel as that used by the Async scheduler, and is hence similarly affected by theASYNC_CONFIGenvironment variable.