@jam3/wait
v1.0.0
Published
Wait a specific amount of time and return a promise, "setTimeout promisified"
Downloads
54
Readme
wait
Minimalistic library that promisified setTimeout
.
Installation
npm install @jam3/wait
Usage
Basic usage
const wait = require('@jam3/wait');
wait(1500).then(callback);
Async/Await example
const wait = require('@jam3/wait');
async function animate() {
await wait(0); // Wait for JS to dequeue this call and do some rending in the meanwhile
console.log('Waited at least 0 milliseconds');
}
Promises example
const wait = require('@jam3/wait');
async function runProcess() {
...
await Promise.all([setTimer, other]);
...
}
async setTimer() {
return await wait(1000);
}
Alternatives
If you want a more complete library, with a couple extra bytes, checkout delay