Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Functions

  • abort<T>(signal: AbortSignal, promise: Promise<T>): Promise<{ aborted: true } | { aborted: false; result: T }>
  • Returns a promise that either resolves with the result of promise, or a value that indicates the execution was aborted.

    Note: Because Promises in JS cannot be canceled, an abort signal will not cancel the execution of the promise.

    Type Parameters

    • T

    Parameters

    • signal: AbortSignal

      A signal that communicates the process should be aborted.

    • promise: Promise<T>

      A promise who's value will be returned if not aborted.

    Returns Promise<{ aborted: true } | { aborted: false; result: T }>

    A value indicating if the process was aborted, or the value of promise.

  • asArray<T>(generator: AsyncGenerator<T, any, unknown>): Promise<T[]>
  • Converts an async generator to an array of results.

    Type Parameters

    • T

    Parameters

    • generator: AsyncGenerator<T, any, unknown>

      The generator to convert.

    Returns Promise<T[]>

    A promise that resolves with an array of results yielded by the generator.

  • delay(ms: number): Promise<void>
  • delay<T>(ms: number, promise: Promise<T>): Promise<T>
  • Returns a promise that resolves successfully after the given delay.

    Parameters

    • ms: number

      The delay in milliseconds.

    Returns Promise<void>

  • Delays the resolution of promise by the given delay.

    Type Parameters

    • T

    Parameters

    • ms: number

      The delay in milliseconds.

    • promise: Promise<T>

      The promise to delay.

    Returns Promise<T>

  • retry<T>(process: (() => Promise<T>), opts?: RetryOptions): Promise<T>
  • Executes and reattempts execution of an asynchronous function if it throws an error. By default, this function will only retry once and reexecute immediately after the previous execution throws. You can configure the number of retry attempts and delays with the maxRetries and delaysInMs options.

    The delaysInMs is an array of delays in milliseconds for each retry attempt. If there are more retry attempts than delays, the last delay will be used.

    Type Parameters

    • T

    Parameters

    • process: (() => Promise<T>)

      The process to execute.

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

    • opts: RetryOptions = {}

      Options to configure retry behavior.

    Returns Promise<T>

    A promise that resolves with a successful value, or the original rejected value if the process fails.

  • timeout(ms: number): Promise<void>
  • timeout<T>(ms: number, promise: Promise<T>): Promise<T>
  • Returns a promise that will reject after the given duration.

    Parameters

    • ms: number

      A duration in milliseconds.

    Returns Promise<void>

  • Assigns a timeout to the given promise, where if the promise doesn't complete within the given duration an exception will be thrown.

    Type Parameters

    • T

    Parameters

    • ms: number

      The timeout, in milliseconds.

    • promise: Promise<T>

      The promise to assign a timeout to.

    Returns Promise<T>