The duration to wait.
// sleep 5 seconds
await sleep(Duration.seconds(5));
// sleep 10 minutes unless interrupted by an event
const promise = sleep(Duration.minutes(10));
events.on('someEvent', promise.interrupt);
await promise;
Sleeps for a given duration, with units defaulting to milliseconds. This is essentially a promisified version
of setTimeout
. May be interrupted by calling interrupt()
on the returned InterruptablePromise
.
The quantity of duration to wait.
Optional
unit: UnitThe Duration.Unit
in which quantity is specified, defaulting to milliseconds.
// sleep 5 seconds
await sleep(5000);
// sleep 10 minutes unless interrupted by an event
const promise = sleep(10, Duration.Unit.MINUTES);
events.on('someEvent', promise.interrupt);
await promise;
Sleeps for a given
Duration
. This is essentially a promisified version ofsetTimeout
. May be interrupted by callinginterrupt()
on the returnedInterruptablePromise
.