Options
All
  • Public
  • Public/Protected
  • All
Menu

Module async

Index

References

Variables

References

Renames and re-exports AsyncUtils

Variables

AsyncUtils: { LazyPromise: typeof LazyPromise; allSettled: (<A>(collection: A) => Promise<{ -readonly [ K in keyof A]: SettleResult<Awaited<A[K]>> }>); any: (<T>(iterable: Iterable<Promise<T>>) => Promise<T>); filter: (<T>(collection: T[], predicate: AsyncFunction<[T, any, any], boolean>) => Promise<T[]>); map: { <T>(collection: T): Promise<Tuple<T>>; <T, R>(collection: ArrayLike<T>, iteratee?: ArrayIteratee<T, Promise<R>>): Promise<R[]>; <T, R>(collection: Record<string, T>, iteratee?: RecordIteratee<T, Promise<R>>): Promise<R[]>; (collection: any, iteratee?: any): Promise<any[]> }; timeout: (<T>(executor: PromiseExecutor<T>, timeout?: number) => Promise<T>) } = ...

AsyncUtils

since

5.18.0

Type declaration

  • LazyPromise: typeof LazyPromise
  • allSettled: (<A>(collection: A) => Promise<{ -readonly [ K in keyof A]: SettleResult<Awaited<A[K]>> }>)
      • <A>(collection: A): 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: Iterable<Promise<T>>) => Promise<T>)
      • <T>(iterable: Iterable<Promise<T>>): 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: T[], predicate: AsyncFunction<[T, any, any], boolean>) => Promise<T[]>)
      • <T>(collection: T[], predicate: AsyncFunction<[T, any, any], boolean>): 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: T): Promise<Tuple<T>>; <T, R>(collection: ArrayLike<T>, iteratee?: ArrayIteratee<T, Promise<R>>): Promise<R[]>; <T, R>(collection: Record<string, T>, iteratee?: RecordIteratee<T, Promise<R>>): Promise<R[]>; (collection: any, iteratee?: any): Promise<any[]> }
      • <T>(collection: T): Promise<Tuple<T>>
      • <T, R>(collection: ArrayLike<T>, iteratee?: ArrayIteratee<T, Promise<R>>): Promise<R[]>
      • <T, R>(collection: Record<string, T>, iteratee?: RecordIteratee<T, Promise<R>>): Promise<R[]>
      • (collection: any, iteratee?: any): Promise<any[]>
      • 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>>

      • Type Parameters

        • T

        • R = any

        Parameters

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

        Returns Promise<R[]>

      • Type Parameters

        • T

        • R = any

        Parameters

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

        Returns Promise<R[]>

      • Parameters

        • collection: any
        • Optional iteratee: any

        Returns Promise<any[]>

  • timeout: (<T>(executor: PromiseExecutor<T>, timeout?: number) => Promise<T>)
      • <T>(executor: PromiseExecutor<T>, timeout?: number): 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

        {TimeoutError}

        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>