• Polls a resource until a terminal condition is met or timeout occurs.

    Type Parameters

    • T
    • K = T

    Parameters

    • reload: () => Promise<T>

      Function that fetches the latest state of the resource

    • isTerminal: (obj: T) => boolean

      Function that determines if the current state is terminal

    • transform: (obj: T) => K = ...

      Function that transforms the resource into a new type

    • options: WaitOptions = {}

      Configuration options for polling behavior

    Returns Promise<K>

    The resource in its terminal state

    If the operation exceeds the timeout duration

    const result = await wait(
    () => fetchOrderStatus(orderId),
    (status) => status === 'completed',
    (status) => status === 'completed' ? { status } : undefined,
    { timeoutSeconds: 30 }
    );