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:
erikdubbelboer/node-sleep
sleep
Add
sleep()
,msleep()
andusleep()
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. Thesleep
andmsleep
functions can be implemented like this:If you require
usleep
this module is still required.Usage
sleep.sleep(n)
: sleep forn
secondssleep.msleep(n)
: sleep forn
milisecondssleep.usleep(n)
: sleep forn
microseconds (1 second is 1000000 microseconds)License