New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

worker-timers

Package Overview
Dependencies
Maintainers
1
Versions
260
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.

4.0.29
Source
npm
Version published
Weekly downloads
327K
-15.34%
Maintainers
1
Weekly downloads
 
Created

What is worker-timers?

The worker-timers npm package provides timer functions (setTimeout, setInterval, and clearTimeout) that run in Web Workers. This allows for more accurate timing and less interference from the main thread, which can be beneficial for performance-sensitive applications.

What are worker-timers's main functionalities?

setTimeout

The setTimeout function schedules a function to be executed after a specified delay, in milliseconds. This is similar to the native setTimeout but runs in a Web Worker for more accurate timing.

const { setTimeout } = require('worker-timers');

setTimeout(() => {
  console.log('This runs after 1000ms');
}, 1000);

setInterval

The setInterval function repeatedly calls a function with a fixed time delay between each call. This is similar to the native setInterval but runs in a Web Worker for more consistent intervals.

const { setInterval } = require('worker-timers');

setInterval(() => {
  console.log('This runs every 1000ms');
}, 1000);

clearTimeout

The clearTimeout function cancels a timeout previously established by calling setTimeout. This is similar to the native clearTimeout but works with the worker-timers setTimeout.

const { setTimeout, clearTimeout } = require('worker-timers');

const timeoutId = setTimeout(() => {
  console.log('This will not run');
}, 1000);

clearTimeout(timeoutId);

clearInterval

The clearInterval function cancels a repeated action which was established by a call to setInterval. This is similar to the native clearInterval but works with the worker-timers setInterval.

const { setInterval, clearInterval } = require('worker-timers');

const intervalId = setInterval(() => {
  console.log('This will not run');
}, 1000);

clearInterval(intervalId);

Other packages similar to worker-timers

Keywords

Web Workers

FAQs

Package last updated on 07 Apr 2018

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