[!WARNING] Mostly does not work on mobile https://caniuse.com/sharedworkers
Timers in SharedWorker, shared across browser tabs (within same origin). One timer per delay, many callbacks for each timer.
- Keep timer callbacks in sync betweet tabs.
- Escape the throttling of window timers in inactive tabs.
Install using your preferred package manager, for example NPM:
npm install shared-timers
Use it in your project like this:
import { runTimer, clearTimer } from 'shared-timers'
const firstCallbackId = runTimer(() => {
// Something executed periodically from a newly created `setInterval`.
}, 1000)
const secondCallbackId = runTimer(() => {
// Something executed periodically from the same `setInterval`.
}, 1000)
// Remove callback from timer/execution.
clearTimer(secondCallbackId)