Add sleep() and usleep() to nodejs
Clone or download
Latest commit 1cfcfff Jul 31, 2018
Permalink
Failed to load latest commit information.
.gitignore 2.0.0 Feb 7, 2015
.travis.yml Add travis CI integration Jul 28, 2018
LICENSE.txt Fix license Jun 3, 2015
README.md Fix windows builds Jul 31, 2018
appveyor.yml Fix windows builds Jul 31, 2018
binding.gyp 2.0.0 Feb 7, 2015
index.js msleep (#64) Jan 4, 2017
package-lock.json 5.2.3 Jul 31, 2018
package.json 5.2.3 Jul 31, 2018
sleep.cc Fix windows builds Jul 31, 2018
test.js Fix windows builds Jul 31, 2018

README.md

Build Status Build status FOSSA Status

sleep

Add sleep(), msleep() and usleep() to Node.js, via a C++ binding.

This is mainly useful for debugging.

These calls will block execution of all JavaScript by halting Node.js' event loop!

Alternative

When using nodejs 9.3 or higher it's better to use Atomics.wait which doesn't require compiling this C++ module. The sleep and msleep functions can be implemented like this:

function msleep(n) {
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n);
}
function sleep(n) {
  msleep(n*1000);
}

If you require usleep this module is still required.

Usage

var sleep = require('sleep');
  • sleep.sleep(n): sleep for n seconds
  • sleep.msleep(n): sleep for n miliseconds
  • sleep.usleep(n): sleep for n microseconds (1 second is 1000000 microseconds)

License

FOSSA Status