@zedtech/zedkit-live
Poll an endpoint as a live source
Poll on an interval without overlap, back off on failure, abort on stop, and skip unchanged values.
alpha
Usage
At a glance
- Who: Apps whose backend has no push channel, or that need a backup for one.
- What: Poll on an interval without overlap, back off on failure, abort on stop, and skip unchanged values.
- Use when: Dashboards and lists that tolerate a few seconds of delay.
- Avoid when: Sub-second updates; use a push transport.
- See also: Receive WebSocket messages with reconnect and polling backup
Install
pnpm add @zedtech/zedkit-liveLatest: 0.1.0 (via changesets).
Example
import { pollingSource } from "@zedtech/zedkit-live";
const jobs = pollingSource({
intervalMs: 5000,
poll: (signal) => fetch("/api/jobs", { signal }).then((r) => r.json()),
isEqual: (a, b) => JSON.stringify(a) === JSON.stringify(b),
});Wraps: (none)
Share one live feed between subscribers
Start the transport on the first subscriber, stop it on the last, expose status, and isolate listener errors.
Receive WebSocket messages with reconnect and polling backup
Open a WebSocket on demand, reconnect with jittered exponential backoff, resolve the URL per attempt, and run a fallback source while it is down.