Function waitFor

Runs the callback function every specified interval and returns a Promise that resolves when the callback returns any other value than null, undefined or false. If your callback throws (or Promise rejects) it will stop the interval and reject the returned Promise. To avoid that use:

waitFor(() => promiseReturningFunction().catch(() => null));
// or
waitFor(() => safe(() => functionThatThrows()));
  • Type Parameters

    • T

    Parameters

    • fn: (() => MaybePromise<T>)

      callback function

        • (): MaybePromise<T>
        • Returns MaybePromise<T>

    • options: Options = defaultOptions

      options object

    Returns Promise<T>