Module Incremental.Clock
Incremental has a timing-wheel-based clock, and lets one build incremental values that change as its time passes. One must explicitly call advance_clock
to change incremental's clock; there is no implicit call based on the passage of time.
val sexp_of_t : ('w -> Ppx_sexp_conv_lib.Sexp.t) -> 'w t -> Ppx_sexp_conv_lib.Sexp.t
val default_timing_wheel_config : Timing_wheel.Config.t
The default timing-wheel configuration, with one millisecond precision, and alarms allowed arbitrarily far in the future.
val create : 'w State.t -> ?timing_wheel_config:Timing_wheel.Config.t -> start:Incremental__.Import.Time_ns.t -> unit -> 'w 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 : 'w t -> (Incremental__.Import.Time_ns.t, 'w) 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
is a no-op 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 advance_clock_by : _ t -> Incremental__.Import.Time_ns.Span.t -> unit
advance_clock_by t span = advance_clock t ~to_:(Time_ns.add (now t) span)
val at : 'w t -> Incremental__.Import.Time_ns.t -> (Before_or_after.t, 'w) incremental
at t time
returns an incremental that isBefore
whennow t < time
andAfter
whennow t >= time
.
val after : 'w t -> Incremental__.Import.Time_ns.Span.t -> (Before_or_after.t, 'w) incremental
after t span
isat t (Time_ns.add (now t) span)
.
val at_intervals : 'w t -> Incremental__.Import.Time_ns.Span.t -> (unit, 'w) incremental
at_intervals t interval
returns an incremental whose value changes at time intervals of the form:Time_ns.next_multiple ~base ~after ~interval
where
base
isnow t
whenat_intervals
was called andafter
is the currentnow t
.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 : 'w t -> init:'a -> (Incremental__.Import.Time_ns.t * 'a) list -> ('a, 'w) incremental
step_function t ~init [(t1, v1); ...; (tn, vn)]
returns an incremental whose initial value isinit
and takes on the valuesv1
, ...,vn
in sequence taking on the valuevi
whennow t >= ti
.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 incremental_step_function : 'w t -> ('a Step_function.t, 'w) incremental -> ('a, 'w) incremental
incremental_step_function t i
returns an incremental whose value isStep_function.value f ~at:(now t)
, wheref
is the value ofi
.
val snapshot : 'w t -> ('a, 'w) incremental -> at:Incremental__.Import.Time_ns.t -> before:'a -> ('a, 'w) incremental Core_kernel.Or_error.t
snapshot t 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 in which the time passesat
.snapshot
causesvalue_at
to be necessary during that stabilization 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 t
, because it is impossible to take the snapshot because the time has already passed.