Options
All
  • Public
  • Public/Protected
  • All
Menu

Provides static methods for combining asynchronous promise operations.

Hierarchy

  • Async

Index

Constructors

constructor

Methods

Static inSeries

  • inSeries<T>(items: T[], asyncFunc: (item: T, index?: number) => Promise<any>): Promise<number>
  • This method applies an asynchronous operation against each value of an array of items in series (from left-to-right).

    The async operation function returns a promise that is resolved when the operation completes successfully and rejected when the operation fails. The resolved value should be false if the iteration should break, i.e. terminate prematurely without executing the remaining operations. If any other value is resolved the iteration continues.

    The inSeries method returns a promise that is resolved with the index of the last item that the async operation function has been applied to successfully. The index is -1, if an empty items array has been specified. If the index is less than that of the last element in the items array, operation has terminated prematurely after executing the item with the index returned.

    The returned promise is rejected immediately and inSeries fails fast, if any of the async operations is rejected.

    Type parameters

    • T

    Parameters

    • items: T[]
    • asyncFunc: (item: T, index?: number) => Promise<any>
        • (item: T, index?: number): Promise<any>
        • Parameters

          • item: T
          • Optional index: number

          Returns Promise<any>

    Returns Promise<number>

Static reduce

  • reduce<T, R>(items: T[], asyncFunc: (item: T, previousValue?: R, index?: number) => Promise<R>, initialValue?: R): Promise<R>
  • The reduce method applies an asynchronous operation against an accumulator and each value of an array of items in series (from left-to-right) to reduce it to a single value.

    The operation function is applied in series to each item in the sequence. It returns a promise that is resolved when the operation completes successfully and rejected when the operation fails.

    The value that results from the reduction is resolved in the returned promise. If one of the async operations is rejected, the returned promise is rejected immediately with the value of the rejected promise and reduce fails fast.

    Type parameters

    • T

    • R

    Parameters

    • items: T[]
    • asyncFunc: (item: T, previousValue?: R, index?: number) => Promise<R>
        • (item: T, previousValue?: R, index?: number): Promise<R>
        • Parameters

          • item: T
          • Optional previousValue: R
          • Optional index: number

          Returns Promise<R>

    • Optional initialValue: R

    Returns Promise<R>

Static withTimeout

  • withTimeout<T>(timeoutMillis: number, promise: Promise<T>): Promise<T>
  • Returns a promise that rejects after the given number of milliseconds if the passed in promise doesn't resolve or reject in the meantime; otherwise the returned promise resolves or rejects with the passed in promise.

    Type parameters

    • T

    Parameters

    • timeoutMillis: number

      number of milliseconds after which to reject

    • promise: Promise<T>

      a promise

    Returns Promise<T>

Generated using TypeDoc