Primitives / foldkit-primitives/time

Throttle

const · packages/primitives/src/time/throttle.ts:25

Args{ intervalMs: number }
Model{ lastAt: number | null }
MessagesAttempted, Evaluated { now: number }
OutMessagesThrottled { at: number }
Its full type
const Throttle: Bundle.Bundle<
  'Throttle',
  { readonly intervalMs: number },
  { readonly lastAt: number | null },
  | { readonly _tag: 'Attempted' }
  | { readonly _tag: 'Evaluated'; readonly now: number },
  { readonly _tag: 'Throttled'; readonly at: number },
  never,
  never,
  void,
  {},
  {}
>

Leading-edge throttle as a bundle: the first Attempted in an interval surfaces a Throttled OutMessage, the rest are dropped. Attempted reads the clock through a Command, so the check runs against Effect time and tests drive it with TestClock. Trailing-edge needs are Debounce's: pair the two rather than adding a second timer here.

In the guides