Macaw.Data.Clock behaviour (macaw_data v0.21.1)

View Source

The runtime's clock, a behavior over an argument (spec/01 §6.5), so a test's clock holds its state without a global. Moved from macaw_live with the source managers, which read it (dco-tek/macaw/macaw#478 decision 6a, #450, #460).

The runtime reads the clock in one place, the page, once per pulse (spec/01 §6.2). That instant is the surface's now: every request's now, every cell's context now and every event's time. A source manager reads it once for the reads of a burst. No source, component, cell or turn reads a clock.

A clock is given as {module, arg}: {Macaw.Data.Clock.System, nil}, the default, or {Macaw.Data.Clock.Manual, clock} in a test.

Summary

Types

t()

A clock as the runtime takes it: its module and its argument.

Callbacks

Cancels a timer send_after/4 armed; :ok whether or not it had fired.

Monotonic milliseconds, for debounces, ticks, backoffs and timeouts.

The wall time, UTC.

Sends message to pid after ms milliseconds; the timer's reference.

Functions

A timer canceled.

Whether a value is a clock: {module, arg} of a loaded module exporting the four callbacks. A clock: that isn't one is {[:clock], {:type, :clock}}.

The clock's monotonic milliseconds.

The clock's wall time.

A timer on the clock: message sent to pid after ms.

Types

t()

@type t() :: {module(), term()}

A clock as the runtime takes it: its module and its argument.

Callbacks

cancel(arg, reference)

@callback cancel(arg :: term(), reference()) :: :ok

Cancels a timer send_after/4 armed; :ok whether or not it had fired.

monotonic_ms(arg)

@callback monotonic_ms(arg :: term()) :: integer()

Monotonic milliseconds, for debounces, ticks, backoffs and timeouts.

now(arg)

@callback now(arg :: term()) :: DateTime.t()

The wall time, UTC.

send_after(arg, pid, message, ms)

@callback send_after(arg :: term(), pid(), message :: term(), ms :: non_neg_integer()) ::
  reference()

Sends message to pid after ms milliseconds; the timer's reference.

Functions

cancel(arg, ref)

@spec cancel(t(), reference()) :: :ok

A timer canceled.

clock?(arg1)

@spec clock?(term()) :: boolean()

Whether a value is a clock: {module, arg} of a loaded module exporting the four callbacks. A clock: that isn't one is {[:clock], {:type, :clock}}.

monotonic_ms(arg)

@spec monotonic_ms(t()) :: integer()

The clock's monotonic milliseconds.

now(arg)

@spec now(t()) :: DateTime.t()

The clock's wall time.

send_after(arg, pid, message, ms)

@spec send_after(t(), pid(), term(), non_neg_integer()) :: reference()

A timer on the clock: message sent to pid after ms.