sleeping

sleep the flow

Usage no npm install needed!

<script type="module">
  import sleeping from 'https://cdn.skypack.dev/sleeping';
</script>

README

Build Status

Usage

const sleeping = require('sleeping')
// sync mode
const time1 = Date.now();
sleep.for(10000);
const time2 = Date.now();
assert(time2 - time1 >= 10000);
// async mode
const time1 = Date.now();
sleep.forAsync(6000)
    .then(() => {
        const time2 = Date.now();
        assert(time2 - time1 >= 6000);
    });
// with callback
const time1 = Date.now();
sleep.forAsync(6000, () => {
    const time2 = Date.now();
    assert(time2 - time1 >= 6000);
    done();
});

// with async functions

async() =>{
    const time1 = Date.now();
    asleep sleep.forAsync(6000)
    const time2 = Date.now();
    assert(time2 - time1 >= 6000);
}

Install

This method block the nodejs event loop

$ npm install sleeping

API Documentation sleeping -> Object

sleeping.for(delay) -> undefined

the param is the time that is event loop will be blocked

sleeping.forAsync(delay,cb) -> Promise

the param is the time that is event loop will be blocked, if the cb is not given return a promise that is resolved when the block is resolved.