Primitives / foldkit-primitives/time
Throttle
const · packages/primitives/src/time/throttle.ts:25
| Args | { intervalMs: number } |
|---|---|
| Model | { lastAt: number | null } |
| Messages | Attempted, Evaluated { now: number } |
| OutMessages | Throttled { 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
- Find one by the jobPrimitives / foldkit-primitives
- The mapPrimitives / foldkit-primitives
- Rules every primitive keepsPrimitives / foldkit-primitives
- foldkit-primitives/timePrimitives / Time
- debounce and ThrottlePrimitives / Time