Package Exports
- worker-timers
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 (worker-timers) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
worker-timers
A replacement for setInterval() and setTimeout() which works in unfocused windows.
Motivation
For scripts that rely on WindowTimers like setInterval() or setTimeout() things get confusing when the site which the script is running on loses focus. Chrome, Firefox and maybe others throttle the frequency of firing those timers to a maximum of once per second in such a situation. However this is only true for the main thread and does not affect the behavior of Web Workers. Therefore it is possible to avoid the throttling by using a worker to do the actual scheduling. This is exactly what WorkerTimers do.
Getting Started
WorkerTimers are available as a package on npm. Simply run the following command to install it:
npm install worker-timersYou can then require the workerTimers instance from within your code like this:
import * as workerTimers from 'worker-timers';The usage is exactly the same as with the corresponding functions on the global scope.
var intervalId = workerTimers.setInterval(() => {
// do something many times
}, 100);
workerTimers.clearInterval(intervalId);
var timeoutId = workerTimers.setTimeout(() => {
// do something once
}, 100);
workerTimers.clearTimeout(timeoutId);