Primitives / foldkit-primitives/time

Timer

const · packages/primitives/src/time/timer.ts:22

Args{ intervalMs: number }
Model{ count: number, running: boolean }
MessagesStarted, Stopped, Ticked
Its full type
const Timer: Bundle.Bundle<
  'Timer',
  { readonly intervalMs: number },
  { readonly count: number; readonly running: boolean },
  | { readonly _tag: 'Started' }
  | { readonly _tag: 'Stopped' }
  | { readonly _tag: 'Ticked' },
  never,
  never,
  never,
  void,
  {},
  {}
>

A timer as a bundle: a count in the Model, advanced by a tick stream while running. The clock is Effect's, so tests drive it with TestClock instead of waiting. For a clock whose running or interval the parent's Model decides, use the ticks entry instead.

In the guides