blocking-sleep
v1.0.0
Published
Library to provide simple, blocking sleep functionality. Designed to replicate Python's Time.sleep()
Readme
blocking-sleep
NodeJS Library to provide simple sleep functionality. Designed to replicate Python's Time.sleep() function.
Installation
npm install blocking-sleepUsage
First import the library...
const sleep = require('blocking-sleep');Then use the sleep(seconds) function anywhere in your code! sleep() is blocking, so node will not move on until the specified time has elapsed.
let start = new Date();
sleep(5);
let end = new Date();
let diff = end - start //=> 5000 (milliseconds)If you would like to sleep for a time shorter than a second, you can pass in floating point values to specify a sleeptime in milliseconds!
let start = new Date();
sleep(.500);
let end = new Date();
let diff = end - start //=> 500 (milliseconds)