Variable concurrencyConst

concurrency: {
    any: (<T>(iterable: Iterable<Promise<T>, any, any>) => Promise<T>);
    debounce: (<T>(runner: T, wait: number) => T);
    limit: (<T>(runner: T, concurrencyNumber: number) => T);
    reuse: (<T>(runner: T, duration?: number, maxHandles?: number) => T & {
        __wrap_global__: {
            duration: number;
            handles: LRUMap<string, {
                timeout: number;
                value: any;
            }>;
        };
    });
    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>, any, any>) => 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>, any, any>

        Returns Promise<T>

        5.7.0

        Error list

  • debounce: (<T>(runner: T, wait: number) => T)
      • <T>(runner, wait): 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

        Type Parameters

        Parameters

        • runner: T
        • wait: number

          wait milliseconds before last time invocation

        Returns T

        5.18.0

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

        Type Parameters

        Parameters

        • runner: T

          async operation function

        • concurrencyNumber: number

          max concurrency number

        Returns T

        the concurrency limited function wrapper

        5.15.0

  • reuse: (<T>(runner: T, duration?: number, maxHandles?: number) => T & {
        __wrap_global__: {
            duration: number;
            handles: LRUMap<string, {
                timeout: number;
                value: any;
            }>;
        };
    })
      • <T>(runner, duration?, maxHandles?): T & {
            __wrap_global__: {
                duration: number;
                handles: LRUMap<string, {
                    timeout: number;
                    value: any;
                }>;
            };
        }
      • reuse values in specific duration for async functions

        Type Parameters

        Parameters

        • runner: T

          must be an async function

        • duration: number = 1000

          default 1000 milliseconds

        • maxHandles: number = 1000

          different cache values for parameters

        Returns T & {
            __wrap_global__: {
                duration: number;
                handles: LRUMap<string, {
                    timeout: number;
                    value: any;
                }>;
            };
        }

        5.22.0

  • series: (<T>(...asyncOperations: T) => Promise<SeriesResult<T>>)
      • <T>(...asyncOperations): 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

        Type Parameters

        Parameters

        • Rest...asyncOperations: T

          async operations

        Returns Promise<SeriesResult<T>>

        5.14.0

        const [res1, res2, res3] = await series(
        () => fetch(1),
        () => fetch(2),
        () => fetch(3)
        )
  • synchronized: (<T>(func: T) => T)
      • <T>(func): T
      • let async function only invoke at once in same time

        Type Parameters

        Parameters

        • func: T

          the function to be processed

        Returns T

        the wrapped function instance

        5.20.0

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

        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

        5.15.0

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