package rtime

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

Timelines for React.

Rtime manages time stamp events, delayed events and delayed signals along timelines. The client chooses the concrete timeline by providing an absolute notion of time. Running the timeline at the appropriate pace is left to the client.

See examples of use.

Release 0.9.3 - Daniel Bünzli <daniel.buenzli at erratique.ch>

Creating and running timelines

type time = float

The type for absolute times.

type duration = float

The type for durations.

type t

The type for timelines.

val create : ?earlier:(t -> unit) -> (unit -> time) -> t

create earlier now is a timeline whose absolute current time is defined by calling the function now. earlier is called with the timeline as an argument whenever a new deadline is scheduled before all the others on the line; this can be used to unblock a sleeping thread.

Warning earlier must not perform React update cycles (because it may very likely be called during an update cycle).

val now : t -> time

now l is the current time on the timeline.

val wakeup : t -> duration option

wakeup l is the duration until the next deadline on the timeline (if any). If duration is negative, the timeline is late.

val progress : ?exec:bool -> t -> unit

progress exec l immediatly removes the next deadline from the timeline and if exec is true (default) executes it.

Warning. Deadline executions usually perform React update cycles.

Time stamp events

On a time stamp event occurence we distinguish :

  • Its stamp, the occurence's value.
  • Its schedule, the time for which the occurence was requested.
  • Its occurence time, the time at which it actually occurs.

The schedule and the occurence time may not coincide.

val stamp : ?stop:'a React.event -> (time -> time -> 'b) -> t -> time -> 'b React.event

stamp stop occ l t is an event such that :

  1. A single occurence is scheduled for t on l.
  2. The occurence's stamp is occ t t' with t' the occurence time.
  3. No occurence is generated after a stop occurs (existing deadlines are removed) or if t is earlier than now l when stamp gets executed.
val stamps : ?stop:'a React.event -> ?start:time -> (time -> time -> 'b * time) -> t -> 'b React.event

stamps stop start occ l is an event such that :

  1. The first occurence is scheduled for start (defaults to now l).
  2. At each occurence time t, occ start t returns the stamp for the current occurence and the time of the next schedule. If the latter is earlier or equal to t no new occurence is scheduled.
  3. No occurences are generated after a stop occurs (existing deadlines are removed) or if start is earlier than now l when stamps gets exectued.

Delays

val delay_e : ?stop:'a React.event -> t -> duration -> 'b React.event -> 'b React.event

delay_e stop l d e is an event such that :

  1. Occurences are those of e delayed by d units of time on l.
  2. No occurences are generated after stop occurs (existing deadlines are removed).
val delay_s : ?eq:('b -> 'b -> bool) -> ?stop:'a React.event -> t -> duration -> 'b -> 'b React.signal -> 'b React.signal

delay_s eq stop l d i s is :

S.hold ?eq i (S.delay stop l d (S.changes s))
OCaml

Innovation. Community. Security.