IntervalExecutor – Periodically executes a callback and emits its result as a window CustomEvent.
Useful for broadcasting regular updates (e.g., polling data, status, or timer-based tasks).
The function to invoke on each interval. Receives an emit function as its argument (i.e., callback(emit)).
Unique identifier for this executor (used as eventName fallback).
Interval duration in seconds.
Name for the CustomEvent emitted on each run (falls back to id if not set).
const exec = new IntervalExecutor({ callback: emit => emit(Date.now()), duration: 1, eventName: "heartbeat"});window.addEventListener("heartbeat", e => console.log("Tick:", e.detail)); Copy
const exec = new IntervalExecutor({ callback: emit => emit(Date.now()), duration: 1, eventName: "heartbeat"});window.addEventListener("heartbeat", e => console.log("Tick:", e.detail));
Initialize and start periodic execution.
The executed callback.
CustomEvent name for emissions.
The unique identifier for this interval instance.
Internal .setInterval handle.
Emit the given value as a CustomEvent (eventName) on window.
Value to send in event.detail.
Start (or restart) the interval. Immediately triggers a callback on start.
Stop the current interval (if running).
IntervalExecutor – Periodically executes a callback and emits its result as a window CustomEvent.
Useful for broadcasting regular updates (e.g., polling data, status, or timer-based tasks).
Param: options
Param: options.callback
The function to invoke on each interval. Receives an emit function as its argument (i.e., callback(emit)).
Param: options.id
Unique identifier for this executor (used as eventName fallback).
Param: options.duration
Interval duration in seconds.
Param: options.eventName
Name for the CustomEvent emitted on each run (falls back to id if not set).
Example