node-sleep

by erikdubbelboer

erikdubbelboer /node-sleep

Add sleep() and usleep() to nodejs

428 Stars 43 Forks Last release: Not found MIT License 77 Commits 13 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

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.

Note that because this is a C++ module, it will need to be built on the system you are going to use it on.

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:
js
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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.