Options
All
  • Public
  • Public/Protected
  • All
Menu

Documentation for async-wait-until v2.0.12

This module implements a function that waits for a given predicate to be truthy. Relies on Promises and supports async/await.

Index

async-wait-until

default

Renames and re-exports waitUntil

Const waitUntil

  • waitUntil<T>(predicate: Predicate<T>, options?: number | Options, intervalBetweenAttempts?: number): Promise<T>
  • Waits for predicate to be truthy and resolves a Promise

    throws

    TimeoutError An exception thrown when the specified timeout interval passes but the predicate doesn't return a truthy value

    throws

    Error

    see

    TruthyValue

    see

    FalsyValue

    see

    Options

    Type parameters

    Parameters

    • predicate: Predicate<T>

      A predicate function that checks the condition, it should return either a truthy value or a falsy value

    • Optional options: number | Options

      Options object (or (deprecated): a maximum wait interval, 5000 ms by default)

    • Optional intervalBetweenAttempts: number

      (deprecated) Interval to wait for between attempts, optional, 50 ms by default

    Returns Promise<T>

    A promise to return the given predicate's result, once it resolves with a truthy value

Defaults

DEFAULT_INTERVAL_BETWEEN_ATTEMPTS_IN_MS

DEFAULT_INTERVAL_BETWEEN_ATTEMPTS_IN_MS: 50 = 50

Default interval between attempts, in milliseconds

DEFAULT_TIMEOUT_IN_MS

DEFAULT_TIMEOUT_IN_MS: 5000 = 5000

Default timeout, in milliseconds

WAIT_FOREVER

WAIT_FOREVER: number = Number.POSITIVE_INFINITY

Timeout that represents infinite wait time

Common Types

Private FalsyValue

FalsyValue: null | undefined | false | "" | 0 | void

A type that represents a falsy value

Options

Options: { intervalBetweenAttempts?: number; timeout?: number }

Options that allow to specify timeout or time interval between consecutive attempts

Type declaration

  • Optional intervalBetweenAttempts?: number
    property

    Interval to wait for between attempts, optional, 50 ms by default

  • Optional timeout?: number
    property

    Maximum wait interval, 5000 ms by default

Private Predicate

Predicate<T>: () => T | Promise<T>

Type parameters

Type declaration

Private PredicateReturnValue

PredicateReturnValue: TruthyValue | FalsyValue

A type that represents a Predicate's return value

Private TruthyValue

TruthyValue: Record<string, unknown> | unknown[] | symbol | ((...args: unknown[]) => unknown) | Exclude<number, 0> | Exclude<string, ""> | true

A type that represents a truthy value

Generated using TypeDoc