Options
All
  • Public
  • Public/Protected
  • All
Menu

Module concurrency

Index

Variables

Variables

concurrency: { any: <T>(iterable: Iterable<Promise<T>>) => Promise<T>; debounce: <T>(runner: T, wait: number) => T; limit: <T>(runner: T, concurrencyNumber: number) => T; series: <T>(...asyncOperations: T) => Promise<SeriesResult<T>>; synchronized: <T>(func: T) => T; timeout: <T>(runner: T, timeout?: number) => T } = ...

concurrency functions

Type declaration

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

  • debounce: <T>(runner: T, wait: number) => T
      • <T>(runner: T, wait: number): T
      • concurrency simply debounce function it will create a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked

        since

        5.18.0

        Type parameters

        Parameters

        • runner: T
        • wait: number

          wait milliseconds before last time invocation

        Returns T

  • limit: <T>(runner: T, concurrencyNumber: number) => T
      • <T>(runner: T, concurrencyNumber: number): T
      • limit concurrent for parallel operations

        since

        5.15.0

        Type parameters

        Parameters

        • runner: T

          async operation function

        • concurrencyNumber: number

          max concurrency number

        Returns T

        the concurrency limited function wrapper

  • series: <T>(...asyncOperations: T) => Promise<SeriesResult<T>>
      • <T>(...asyncOperations: T): Promise<SeriesResult<T>>
      • run async operations one by one, serially

        and return the result array

        if any operation raise error, the following operations will not be executed

        since

        5.14.0

        example
        const [res1, res2, res3] = await series(
        () => fetch(1),
        () => fetch(2),
        () => fetch(3)
        )

        Type parameters

        Parameters

        • Rest ...asyncOperations: T

          async operations

        Returns Promise<SeriesResult<T>>

  • synchronized: <T>(func: T) => T
      • <T>(func: T): T
      • let async function only invoke at once in same time

        since

        5.20.0

        Type parameters

        Parameters

        • func: T

          the function to be processed

        Returns T

        the wrapped function instance

  • timeout: <T>(runner: T, timeout?: number) => T
      • <T>(runner: T, timeout?: number): T
      • wrap an async function with timeout

        since

        5.15.0

        throws

        {TimeoutError}

        example
        const f = timeout(async() => {}, 1000)
        // f() will throw error if the result is not resolved in one second

        Type parameters

        Parameters

        • runner: T

          async runner please, otherwise the timeout is not meaningful

        • timeout: number = ...

          timeout threshold in milliseconds, default value is 60 seconds

        Returns T