Worker based timers for Stream.io JS-based SDKs and applications
npm install @stream-io/worker-timerA Worker based implementation of the JS Timers API.
``ts
// import the library
import { WorkerTimer } from "@stream-io/worker-timer";
// create an instance
const timer = new WorkerTimer();
// with interval
const id = timer.setInterval(() => {
console.log("Hello World from interval");
}, 1000);
// clear the interval
timer.clearInterval(id);
// with timeout
timer.setTimeout(() => {
console.log("Hello World from timeout");
}, 1000);
// clear the timeout
timer.clearTimeout(id);
`
You can also create a WorkerTimer instance with custom defaults:
`ts``
const timer = new WorkerTimer({
useWorker: false, // will fallback the Platform API
name: "custom-timer", // name of the worker, for debugging purposes
});