1.0.5 • Published 4 years ago

@js-util/promise-sleep v1.0.5

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Promise Sleep

Returns a promise, which resolve after the specified sleep itme (ms)

npm install

npm install --save @js-util/promise-sleep

Example usage

// Importing the module
const promiseSleep = require("@js-util/promise-sleep");

// Await sleep in ms
// 1000 ms -> 1 second
await promiseSleep(1000)

Its code

// Store a reference to the global setTimeout,
// in case it gets replaced (e.g. sinon.useFakeTimers())
const timeoutFunction = setTimeout;

/**
 * @param {Int} timeout in milliseconds to sleep by
 * @return a promise which resolves on timeout, returns no actual value
 */
function promiseSleep(timeout) {
    return new Promise((resolve) => {
        timeoutFunction(resolve, timeout);
    });
}

// Export the function
module.exports = promiseSleep;
1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago