Kepler.Context (Kepler v0.1.0)

Copy Markdown View Source

The values a fire when: condition is evaluated against.

You never build one of these yourself — Kepler.Poller assembles one per watch per tick and hands it to the function compiled from your condition. What matters is which names the condition can use, and what they mean.

Names available in a condition

NameMeaning
valueThis watch's measurement for the current tick.
prevThe previous tick's measurement.
deltavalue - prev.
ratedelta per second — change, not throughput.

For counting aggregates (measure :count) value is the number of events in the tick window, and measure :rate gives you throughput directly, so rate keeps its single meaning of "how fast is this number moving" everywhere.

Referring to other watches

CallReadsTiming
watch(:name)that watch's valuethis tick
met?(:name) or bare namewhether its condition heldthis tick
firing?(:name)whether it is in the firing stateas of the previous tick

All measurements are sampled before any condition runs, and conditions run in dependency order, so watch/1 and met?/1 always see current-tick data regardless of declaration order. firing?/1 deliberately reads the previous tick's outcome: firing state is the output of debouncing, and letting a condition depend on this tick's output would be circular.

A cycle among met?/1 references is a compile error.

Summary

Functions

Whether another watch was in the firing state as of the previous tick.

Whether another watch's condition held on this tick, before debouncing.

The current-tick measurement of another watch.

Types

t()

@type t() :: %Kepler.Context{
  conditions: %{required(atom()) => boolean()},
  delta: number(),
  firing: MapSet.t(atom()),
  prev: number() | nil,
  rate: float(),
  value: number(),
  values: %{required(atom()) => number()},
  watch: atom(),
  window_ms: pos_integer()
}

Functions

firing?(context, name)

@spec firing?(t(), atom()) :: boolean()

Whether another watch was in the firing state as of the previous tick.

Compiled from firing?(:name). Unlike met?/2 this reflects the debounced outcome — it stays true through a cooldown: window and only becomes true after a sustained: window has elapsed.

met?(context, name)

@spec met?(t(), atom()) :: boolean()

Whether another watch's condition held on this tick, before debouncing.

Compiled from met?(:name) or from a bare reference to a declared watch.

value(context, name)

@spec value(t(), atom()) :: number()

The current-tick measurement of another watch.

Compiled from watch(:name) in a condition. Raises if the watch produced no data, which cannot happen in practice: the poller skips any watch whose dependencies are missing for the tick.