Skip to main content
SetInterval runs actions on a repeating timer. Each tick fires on_tick, and the timer stops automatically when a while_ condition becomes false, a count limit is reached, or both. When it stops, on_complete fires one final time.

One-Shot Delay

Set count=1 to fire once after a pause — no separate “delay” action needed. Put your logic in on_complete and it runs when the timer finishes. The button below swaps to a waiting state so the user knows something is happening.

Countdown

Each tick decrements seconds in state, and the display reflects the current value through reactive expressions. When seconds reaches zero, the while_ condition becomes false and the interval stops on its own.

Start and Stop

Store a boolean flag in state and reference it in while_. Any action can flip the flag — the interval checks it on the next tick and stops. Here, one button starts an incrementing counter and another stops it. The same pattern works for periodic server polling with CallTool in on_tick. If neither while_ nor count is set, the interval runs indefinitely until the component tree is replaced.

API Reference

SetInterval Parameters

duration
int
required
Milliseconds between ticks. Passed as a positional argument.
while_
str | None
default:"None"
Condition expression re-evaluated each tick against current state. When it evaluates to falsy, the interval stops and on_complete fires. Serializes as "while" on the wire.
count
int | None
default:"None"
Maximum number of ticks. The interval stops after this many.
on_tick
Action | list[Action] | None
default:"None"
Action(s) to run each tick. $event is the tick number (1, 2, 3, …).
on_complete
Action | list[Action] | None
default:"None"
Action(s) to run when the interval finishes.

Protocol Reference

SetInterval
{
  "action": "setInterval",
  "duration": "number (required)",
  "while?": "string",
  "count?": "number",
  "onTick?": "Action | Action[]",
  "onComplete?": "Action | Action[]"
}
For the complete protocol schema, see SetInterval.