Minimalistic (nano < 30 bytes) library that promisified setTimeout
.
npm install @jam3/wait
const wait = require('@jam3/wait');
wait(1500).then(callback);
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');
}
const wait = require('@jam3/wait');
async function runProcess() {
...
await Promise.all([setTimer, other]);
...
}
async setTimer() {
return await wait(1000);
}
If you want a more complete library, with a couple extra bytes, checkout delay