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

Since

5.18.0

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

        Author

        Theo Sun

        Since

        5.18.0

        Type Parameters

        • A extends [] | readonly unknown[]

        Parameters

        • collection: A

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

  • 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

        Since

        5.7.0

        Throws

        Error list

        Type Parameters

        • T

        Parameters

        • iterable: Iterable<Promise<T>>

        Returns Promise<T>

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

        Author

        Theo Sun

        Since

        5.18.0

        Type Parameters

        • T extends unknown

        Parameters

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

          async predicate

        Returns Promise<T[]>

  • 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

        Author

        Theo Sun

        Since

        5.18.0

        Type Parameters

        • T extends any[] | []

        Parameters

        • collection: T

        Returns Promise<Tuple<T>>

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

        • T

        • R = any

        Parameters

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

        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>>

        Returns Promise<R[]>

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

        • collection: any
        • Optional iteratee: any

        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

        Since

        5.14.0

        Throws

        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>