async-wrappers
Version:
A set of wrapper functions to perform debouncing, throttling, retrying etc.
23 lines (22 loc) • 1.56 kB
TypeScript
import { ReducerCallParameters } from './callReducers';
/**
* @internal
*/
export declare type CallFunction<F extends (...args: any[]) => any, Args extends any[]> = (...args: Args) => Promise<ReturnType<F>>;
/**
* @internal
*
* Utility function that wraps a function and will use a reducer to combine the arguments
* of multiple calls to that function. As the function is not executed until it is invoked
* a promise for the result is returned to the callers.
*
* @param fn The function to wrap.
* @param {?argumentsReducer} callReducer Used to determine the arguments when `fn` is invoked.
* This will be called every time the wrapped function is called.
* If not supplied the default implementation of only using the latest arguments will be used.
* @param onBeforeReduce If supplied this function will be called before the reducer is called.
* @param onAfterReduce If supplied this function will be called if the wrapped function is cancelled.
* @returns
*/
declare const callReduce: <Invoke extends (...args: any[]) => any, Reducer extends import("./callReducers").ArgumentsReducer<Parameters<Invoke>, any> = import("./callReducers").ArgumentsReducer<Parameters<Invoke>, import("./callReducers").ParametersOrArray<Invoke>>>(fn: Invoke, callReducer?: Reducer | undefined, onBeforeReduce?: ((...args: any[]) => any) | undefined, onAfterReduce?: ((...args: any[]) => any) | undefined) => [CallFunction<Invoke, ReducerCallParameters<Reducer, Parameters<Invoke>>>, () => () => void, (error?: Error | undefined) => void];
export default callReduce;