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

atomic-sleep

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

atomic-sleep

Zero CPU overhead, zero dependency, true event-loop blocking sleep

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7M
decreased by-4.92%
Maintainers
1
Weekly downloads
 
Created
Source

Welcome to atomic-sleep ⏱️

Version License: MIT Twitter: davidmarkclem

Zero CPU overhead, zero dependency, true event-loop blocking sleep

Usage

const sleep = require('atomic-sleep')

console.time('sleep')
setTimeout(() => { console.timeEnd('sleep') }, 100) 
sleep(1000)

The console.time will report a time of just over 1000ms despite the setTimeout being 100ms. This is because the event loop is paused for 1000ms and the setTimeout fires immediately after the event loop is no longer blocked (as more than 100ms have passed).

Install

npm install

Run tests

npm test

Support

Node and Browser versions that support both SharedArrayBuffer and Atomics will have (virtually) zero CPU overhead sleep.

For Node, Atomic Sleep can provide zero CPU overhead sleep from Node 8 and up.

For browser support see https://caniuse.com/#feat=sharedarraybuffer and https://caniuse.com/#feat=mdn-javascript_builtins_atomics.

For older Node versions and olders browsers we fall back to blocking the event loop in a way that will cause a CPU spike.

Author

👤 David Mark Clements (@davidmarkclem)

Keywords

FAQs

Package last updated on 09 Mar 2020

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