worker-tick
v0.0.5
Published
[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![bundle][bundle-src]][bundle-href] [![JSDocs][jsdocs-src]][jsdocs-href] [![License][license-src]][license-href]
Downloads
24
Readme
worker-tick
Make setTimeout() and setInterval() timers work stably in background tabs (unfocused browser tabs)
Browsers reduce the frequency of setTimeout() and setInterval() when a browser tab is inactive (e.g., loses focus, switches to another tab, or switches to another application) for performance optimization reasons requestAnimationFrame() does the same thing
Install
Using npm:
npm install worker-tick
Usage
Refer to development in the repository
import workerTick from 'worker-tick'
- window.setInterval(console.log, 1000, 1, 2, 3)
+ workerTick.setInterval(console.log, 1000, 1, 2, 3)
// => Printouts per second: 1 2 3
// clear
const timerId = workerTick.setInterval(console.log, 1000, 1, 2, 3)
workerTick.clearInterval(timerId)
// setTimeout() Same as above