Package Exports
- shared-timers
- shared-timers/dist/shared-timers.js
- shared-timers/dist/shared-timers.umd.cjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (shared-timers) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Shared Timers
[!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.
Motivation
- Keep timer callbacks in sync betweet tabs.
- Escape the throttling of window timers in inactive tabs.
Getting Started
Install using your preferred package manager, for example NPM:
npm install shared-timersUse 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)