A promisified version of setTimeout
.
const wait = require('@trenskow/wait');
await wait('2s');
Waits two seconds.
Internally it uses the ms package – see that package for documentation.
You can also cancel the wait before the specified time.
const waiter = wait('2s');
setTimeout(waiter.cancel, 1000);
await waiter;
/* returns after one second instead of two because `setTimeout` triggers the elapse function of `waiter`. */
MIT (see license)