blocking-sleep

1.0.0 • Public • Published

blocking-sleep

NodeJS Library to provide simple sleep functionality. Designed to replicate Python's Time.sleep() function.

Installation

npm install blocking-sleep

Usage

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)

That's it!

/blocking-sleep/

    Package Sidebar

    Install

    npm i blocking-sleep

    Weekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    1.64 kB

    Total Files

    3

    Last publish

    Collaborators

    • a-myers