@trenskow/wait
v1.3.31
Published
A promisified version of `setTimeout`.
Downloads
184
Readme
@trenskow/wait
A promisified version of setTimeout
.
Usage
const wait = require('@trenskow/wait');
await wait('2s');
Waits two seconds.
Time Interval Format
Internally it uses the ms package – see that package for documentation.
Cancelling
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`. */
License
MIT (see license)