Variable AsyncUtilsConst

AsyncUtils: {
    LazyPromise: typeof LazyPromise;
    allSettled: (<A>(collection) => Promise<{
        -readonly [K in keyof A]: SettleResult<Awaited<A[K]>>
    }>);
    any: (<T>(iterable) => Promise<T>);
    filter: (<T>(collection, predicate) => Promise<T[]>);
    map: {
        <T>(collection): Promise<Tuple<T>>;
        <T, R>(collection, iteratee?): Promise<R[]>;
        <T, R>(collection, iteratee?): Promise<R[]>;
        (collection, iteratee?): Promise<any[]>;
    };
    timeout: (<T>(executor, timeout?) => Promise<T>);
} = ...

AsyncUtils

Type declaration

  • LazyPromise: typeof LazyPromise
  • allSettled: (<A>(collection) => Promise<{
        -readonly [K in keyof A]: SettleResult<Awaited<A[K]>>
    }>)
      • <A>(collection): Promise<{
            -readonly [K in keyof A]: SettleResult<Awaited<A[K]>>
        }>
      • Promise.allSettled() implementation

        Type Parameters

        • A extends [] | readonly unknown[]

        Parameters

        • collection: A

        Returns Promise<{
            -readonly [K in keyof A]: SettleResult<Awaited<A[K]>>
        }>

        Author

        Theo Sun

        Since

        5.18.0

  • any: (<T>(iterable) => Promise<T>)
      • <T>(iterable): Promise<T>
      • Promise.any implementation

        just ref the MDN document

        Promise.any() takes an iterable of Promise objects and, as soon as one of the promises in the iterable fulfils, returns a single promise that resolves with the value from that promise. If no promises in the iterable fulfil (if all of the given promises are rejected), then throw the array of errors

        Type Parameters

        • T

        Parameters

        • iterable: Iterable<Promise<T>>

        Returns Promise<T>

        Since

        5.7.0

        Throws

        Error list

  • filter: (<T>(collection, predicate) => Promise<T[]>)
      • <T>(collection, predicate): Promise<T[]>
      • AsyncUtils.filter, filter values by async predicate function

        Type Parameters

        • T extends unknown

        Parameters

        • collection: T[]
        • predicate: AsyncFunction<[T, any, any], boolean>

          async predicate

        Returns Promise<T[]>

        Author

        Theo Sun

        Since

        5.18.0

  • map: {
        <T>(collection): Promise<Tuple<T>>;
        <T, R>(collection, iteratee?): Promise<R[]>;
        <T, R>(collection, iteratee?): Promise<R[]>;
        (collection, iteratee?): Promise<any[]>;
    }
      • <T>(collection): Promise<Tuple<T>>
      • AsyncUtils.map, mapping values with async iteratee functions

        Type Parameters

        • T extends any[] | []

        Parameters

        • collection: T

        Returns Promise<Tuple<T>>

        Author

        Theo Sun

        Since

        5.18.0

      • <T, R>(collection, iteratee?): Promise<R[]>
      • Type Parameters

        • T

        • R = any

        Parameters

        • collection: ArrayLike<T>
        • Optional iteratee: ArrayIteratee<T, Promise<R>>
          Optional

        Returns Promise<R[]>

      • <T, R>(collection, iteratee?): Promise<R[]>
      • Type Parameters

        • T

        • R = any

        Parameters

        • collection: Record<string, T>
        • Optional iteratee: RecordIteratee<T, Promise<R>>
          Optional

        Returns Promise<R[]>

      • (collection, iteratee?): Promise<any[]>
      • Parameters

        • collection: any
        • Optional iteratee: any
          Optional

        Returns Promise<any[]>

  • timeout: (<T>(executor, timeout?) => Promise<T>)
      • <T>(executor, timeout?): Promise<T>
      • create a promise with timeout, if time is up but no result/error resolved by promise, will throw an error

        Type Parameters

        • T

        Parameters

        • executor: PromiseExecutor<T>

          the promise executor

        • timeout: number = ...

          the timeout in milliseconds, e.g. 10000 means 10 seconds, and default value is 60 seconds

        Returns Promise<T>

        Since

        5.14.0

        Throws

Since

5.18.0