Socket
Book a DemoInstallSign in
Socket

worker-timers

Package Overview
Dependencies
Maintainers
1
Versions
268
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

worker-timers

A replacement for setInterval() and setTimeout() which works in unfocused windows

Source
npmnpm
Version
3.0.1
Version published
Weekly downloads
335K
-6.84%
Maintainers
1
Weekly downloads
 
Created
Source

worker-timers

A replacement for setInterval() and setTimeout() which works in unfocused windows.

tests dependencies version

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-timers

You 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);

Keywords

clearInterval

FAQs

Package last updated on 30 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts