Module Make.Clock
val sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t
val default_timing_wheel_config : Core_kernel.Timing_wheel_ns.Config.t
The default timing-wheel configuration, with one millisecond precision with alarms up to 30 days in the future.
val create : ?timing_wheel_config:Core_kernel.Timing_wheel_ns.Config.t -> start:Incremental__.Import.Time_ns.t -> unit -> t
val alarm_precision : t -> Incremental__.Import.Time_ns.Span.t
The
alarm_precision
of the underlying timing wheel.
val timing_wheel_length : t -> int
val now : t -> Incremental__.Import.Time_ns.t
now t
returns the current time of incremental's clock.
val watch_now : t -> Incremental__.Import.Time_ns.t incremental
watch_now t
returns an incremental that tracks the current time.
val advance_clock : t -> to_:Incremental__.Import.Time_ns.t -> unit
advance_clock t ~to_
moves incremental's clock forward toto_
.advance_clock
raises ifto_ < now t
. As withVar.set
, the effect ofadvance_clock
is not seen on incremental values until the next stabilization. UnlikeVar.set
, callingadvance_clock
during stabilization raises.In certain pathological cases,
advance_clock
can raise due to it detecting a cycle in the incremental graph.
val at : t -> Incremental__.Import.Time_ns.t -> Before_or_after.t incremental
at time
returns an incremental that isBefore
whennow () <= time
andAfter
whennow () >= time + alarm_precision
. Whennow ()
is betweentime
andtime + alarm_precision
,at time
might beBefore
orAfter
, due to the fundamental imprecision of the timing wheel. One is guaranteed that anat
never becomesAfter
too early, but it may becomeAfter
up toalarm_precision
late.after span
isat (Time_ns.add (now ()) span)
.
val after : t -> Incremental__.Import.Time_ns.Span.t -> Before_or_after.t incremental
val at_intervals : t -> Incremental__.Import.Time_ns.Span.t -> unit incremental
at_intervals interval
returns an incremental whose value changes at time intervals of the form:Time_ns.next_multiple ~base ~after ~interval
where
base
isnow ()
whenat_intervals
was called andafter
is the currentnow ()
. As withat
,at_intervals
might fire up toalarm_precision
late.at_intervals
raises ifinterval < alarm_precision
. Theunit t
thatat_intervals
returns has its cutoff set toCutoff.never
, so that although its value is always()
, incrementals that depend on it will refire each time it is set. The result ofat_intervals
remains alive and is updated until the left-hand side of its defining bind changes, at which point it becomes invalid.
val step_function : t -> init:'a -> (Incremental__.Import.Time_ns.t * 'a) list -> 'a incremental
step_function ~init [(t1, v1); ...; (tn, vn)]
returns an incremental whose initial value isinit
and takes on the valuesv1
, ...,vn
in sequence taking on the valuevi
when the clock's time passesti
. As withat
, the steps might take effect up toalarm_precision
late.It is possible for
vi
to be skipped if time advances fromt(i-1)
to some time greater thant(i+1)
.The times must be in nondecreasing order, i.e.
step_function
raises if for somei < j
,ti > tj
.
val snapshot : t -> 'a incremental -> at:Incremental__.Import.Time_ns.t -> before:'a -> 'a incremental Core_kernel.Or_error.t
snapshot value_at ~at ~before
returns an incremental whose value isbefore
beforeat
and whose value is frozen to the value ofvalue_at
during the first stabilization after which the time passesat
.snapshot
causesvalue_at
to be necessary during the first stabilization after which time passesat
even if thesnapshot
node itself is not necessary, but not thereafter (although of coursevalue_at
could remain necessary for other reaspons). The result ofsnapshot
will only be invalidated ifvalue_at
is invalid at the moment of the snapshot.snapshot
returnsError
ifat < now ()
, because it is impossible to take the snapshot because the time has already passed.