package async_kernel

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Async_kernel.Time_sourceSource

Sourcemodule T1 : sig ... end

A time source has a phantom read-write parameter, where write gives permission to call advance and fire_past_alarms.

Sourcemodule Read_write : sig ... end
Sourceval sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t
Sourceval id : _ T1.t -> Id.t

id t returns a unique, consistent identifier which can be used e.g. as a map or hash table key.

include Core_kernel.Invariant.S with type t := t
Sourceval invariant : t -> unit
Sourceval invariant_with_jobs : job: (Async_kernel__.Types.Execution_context.t, Obj.t -> unit, Obj.t) Tuple_pool.Slots.t3 Tuple_pool.Pointer.t Core_kernel.Invariant.t -> t Core_kernel.Invariant.t
Sourceval read_only : [> Core_kernel.read ] T1.t -> t
Sourceval create : ?timing_wheel_config:Timing_wheel.Config.t -> now:Core_kernel.Time_ns.t -> unit -> Core_kernel.read_write T1.t
Sourceval wall_clock : unit -> t

A time source with now t given by wall-clock time (i.e., Time_ns.now) and that is advanced automatically as time passes (specifically, at the start of each Async cycle). There is only one wall-clock time source; every call to wall_clock () returns the same value. The behavior of now is special for wall_clock (); it always calls Time_ns.now (), so it can return times that the time source has not yet been advanced to.

Accessors. now (wall_clock ()) behaves specially; see wall_clock above.

Sourceval next_alarm_fires_at : [> Core_kernel.read ] T1.t -> Core_kernel.Time_ns.t option
Sourceval timing_wheel_now : [> Core_kernel.read ] T1.t -> Core_kernel.Time_ns.t

Removes the special behavior of now for wall_clock; it always returns the timing_wheel's notion of now.

Sourceval advance_directly : [> Core_kernel.write ] T1.t -> to_:Core_kernel.Time_ns.t -> unit

Instead of advance_directly, you probably should use advance_by_alarms. advance_directly t ~to_ advances the clock directly to to_, whereas advance_by_alarms advances the clock in steps, to each intervening alarm. advance_directly approximately determines the set of events to fire, up to timing-wheel alarm precision, whereas advance_by_alarms fires all alarms whose time is <= to_. With advance_directly, you must call fire_past_alarms if you want that behavior (see docs for Timing_wheel.advance_clock vs. Timing_wheel.fire_past_alarms).

Sourceval advance : [> Core_kernel.write ] T1.t -> to_:Core_kernel.Time_ns.t -> unit
  • deprecated [since 2019-06] Use [advance_directly] (to preserve behavior) or [advance_by_alarms]
  • deprecated [since 2019-06] Use [advance_directly_by] (to preserve behavior) or [advance_by_alarms_by]
Sourceval fire_past_alarms : [> Core_kernel.write ] T1.t -> unit
Sourceval advance_by_alarms : ?wait_for:(unit -> unit Async_kernel__.Types.Deferred.t) -> [> Core_kernel.write ] T1.t -> to_:Core_kernel.Time_ns.t -> unit Async_kernel__.Types.Deferred.t

advance_by_alarms t repeatedly calls advance t to drive the time forward in steps, where each step is the minimum of to_ and the next alarm time. After each step, advance_by_alarms waits for the result of wait_for to become determined before advancing. By default, wait_for will be Scheduler.yield () to allow the triggered timers to execute and potentially rearm for subsequent steps. The returned deferred is filled when to_ is reached.

advance_by_alarms is useful in simulation when one wants to efficiently advance to a time in the future while giving periodic timers (e.g., resulting from every) a chance to fire with approximately the same timing as they would live.

Sourceval advance_by_alarms_by : ?wait_for:(unit -> unit Async_kernel__.Types.Deferred.t) -> [> Core_kernel.write ] T1.t -> Core_kernel.Core_kernel_private.Time_ns_alternate_sexp.Span.t -> unit Async_kernel__.Types.Deferred.t

advance_by_alarms_by ?wait_for t by is equivalent to: advance_by_alarms ?wait_for t ~to_:(Time_ns.add (now t) by)

Sourcemodule Continue : sig ... end
Sourceval run_repeatedly : ?start:unit Async_kernel__.Types.Deferred.t -> ?stop:unit Async_kernel__.Types.Deferred.t -> ?continue_on_error:bool -> ?finished:unit Ivar.t -> [> Core_kernel.read ] T1.t -> f:(unit -> unit Async_kernel__.Types.Deferred.t) -> continue:Continue.t -> unit

See Clock.every for documentation.

The functions below here are the same as in clock_intf.ml, except they take an explicit t argument. See Clock_intf for documentation.

Sourceval run_at : [> Core_kernel.read ] T1.t -> Core_kernel.Time_ns.t -> ('a -> unit) -> 'a -> unit
Sourceval at : [> Core_kernel.read ] T1.t -> Core_kernel.Time_ns.t -> unit Async_kernel__.Types.Deferred.t
Sourceval after : [> Core_kernel.read ] T1.t -> Core_kernel.Core_kernel_private.Time_ns_alternate_sexp.Span.t -> unit Async_kernel__.Types.Deferred.t
Sourceval with_timeout : [> Core_kernel.read ] T1.t -> Core_kernel.Core_kernel_private.Time_ns_alternate_sexp.Span.t -> 'a Async_kernel__.Types.Deferred.t -> [ `Timeout | `Result of 'a ] Async_kernel__.Types.Deferred.t
Sourcemodule Event : sig ... end
Sourceval at_varying_intervals : ?stop:unit Async_kernel__.Types.Deferred.t -> [> Core_kernel.read ] T1.t -> (unit -> Core_kernel.Core_kernel_private.Time_ns_alternate_sexp.Span.t) -> unit Tail.Stream.t
Sourceval at_intervals : ?start:Core_kernel.Time_ns.t -> ?stop:unit Async_kernel__.Types.Deferred.t -> [> Core_kernel.read ] T1.t -> Core_kernel.Core_kernel_private.Time_ns_alternate_sexp.Span.t -> unit Tail.Stream.t
Sourceval every' : ?start:unit Async_kernel__.Types.Deferred.t -> ?stop:unit Async_kernel__.Types.Deferred.t -> ?continue_on_error:bool -> ?finished:unit Ivar.t -> [> Core_kernel.read ] T1.t -> Core_kernel.Core_kernel_private.Time_ns_alternate_sexp.Span.t -> (unit -> unit Async_kernel__.Types.Deferred.t) -> unit

See Clock.every' for documentation.

Sourceval every : ?start:unit Async_kernel__.Types.Deferred.t -> ?stop:unit Async_kernel__.Types.Deferred.t -> ?continue_on_error:bool -> [> Core_kernel.read ] T1.t -> Core_kernel.Core_kernel_private.Time_ns_alternate_sexp.Span.t -> (unit -> unit) -> unit
Sourceval run_at_intervals' : ?start:Core_kernel.Time_ns.t -> ?stop:unit Async_kernel__.Types.Deferred.t -> ?continue_on_error:bool -> [> Core_kernel.read ] T1.t -> Core_kernel.Core_kernel_private.Time_ns_alternate_sexp.Span.t -> (unit -> unit Async_kernel__.Types.Deferred.t) -> unit
Sourceval run_at_intervals : ?start:Core_kernel.Time_ns.t -> ?stop:unit Async_kernel__.Types.Deferred.t -> ?continue_on_error:bool -> [> Core_kernel.read ] T1.t -> Core_kernel.Core_kernel_private.Time_ns_alternate_sexp.Span.t -> (unit -> unit) -> unit
Sourceval of_synchronous : 'a Synchronous_time_source.T1.t -> 'a T1.t

Time_source and Synchronous_time_source are the same data structure and use the same underlying timing wheel. The types are freely interchangeable.

Sourceval to_synchronous : 'a T1.t -> 'a Synchronous_time_source.T1.t
OCaml

Innovation. Community. Security.