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.tThe 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 tval alarm_precision : _ t -> Incremental__.Import.Time_ns.Span.tThe
alarm_precisionof the underlying timing wheel.
val timing_wheel_length : _ t -> intval now : _ t -> Incremental__.Import.Time_ns.tnow treturns the current time of incremental's clock.
val watch_now : 'w t -> (Incremental__.Import.Time_ns.t, 'w) incrementalwatch_now treturns an incremental that tracks the current time.
val advance_clock : _ t -> to_:Incremental__.Import.Time_ns.t -> unitadvance_clock t ~to_moves incremental's clock forward toto_.advance_clockis a no-op ifto_ < now t. As withVar.set, the effect ofadvance_clockis not seen on incremental values until the next stabilization. UnlikeVar.set, callingadvance_clockduring stabilization raises.In certain pathological cases,
advance_clockcan raise due to it detecting a cycle in the incremental graph.
val advance_clock_by : _ t -> Incremental__.Import.Time_ns.Span.t -> unitadvance_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) incrementalat t timereturns an incremental that isBeforewhennow t < timeandAfterwhennow t >= time.
val after : 'w t -> Incremental__.Import.Time_ns.Span.t -> (Before_or_after.t, 'w) incrementalafter t spanisat t (Time_ns.add (now t) span).
val at_intervals : 'w t -> Incremental__.Import.Time_ns.Span.t -> (unit, 'w) incrementalat_intervals t intervalreturns an incremental whose value changes at time intervals of the form:Time_ns.next_multiple ~base ~after ~intervalwhere
baseisnow twhenat_intervalswas called andafteris the currentnow t.at_intervalsraises ifinterval < alarm_precision. Theunit tthatat_intervalsreturns 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_intervalsremains 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) incrementalstep_function t ~init [(t1, v1); ...; (tn, vn)]returns an incremental whose initial value isinitand takes on the valuesv1, ...,vnin sequence taking on the valueviwhennow t >= ti.It is possible for
vito 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_functionraises if for somei < j,ti > tj.
val incremental_step_function : 'w t -> ('a Step_function.t, 'w) incremental -> ('a, 'w) incrementalincremental_step_function t ireturns an incremental whose value isStep_function.value f ~at:(now t), wherefis 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.tsnapshot t value_at ~at ~beforereturns an incremental whose value isbeforebeforeatand whose value is frozen to the value ofvalue_atduring the first stabilization in which the time passesat.snapshotcausesvalue_atto be necessary during that stabilization even if thesnapshotnode itself is not necessary, but not thereafter (although of coursevalue_atcould remain necessary for other reaspons). The result ofsnapshotwill only be invalidated ifvalue_atis invalid at the moment of the snapshot.snapshotreturnsErrorifat < now t, because it is impossible to take the snapshot because the time has already passed.