Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

worker-timers

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

  • 8.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
146K
decreased by-48.17%
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

FAQs

Package last updated on 12 Jul 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc