Function sleep

  • Sleeps for a given Duration. This is essentially a promisified version of setTimeout. May be interrupted by calling interrupt() on the returned InterruptablePromise.

    Parameters

    • duration: Duration

      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;

    Returns InterruptablePromise<void>

  • 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.

    Parameters

    • quantity: number

      The quantity of duration to wait.

    • Optionalunit: Unit

      The 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;

    Returns InterruptablePromise<void>