/** * Regulator * @remarks * Regulator allows you to regulate the number of concurrent processes. * * @example * const reg = new Regulator(2); * reg.onProcess(async example(args) => { * // do something with args * }); * * reg.invoke([1, 2, 3]); (all example will be called with [1, 2, 3] but only 2 at a time will be processed) */ export interface RegulatorOf { /** * @remarks * Set the maximum number of concurrent processes. * Default is 1. * @param n * @returns > */ maxConcurrency(n: number): RegulatorOf; /** * @remarks * Set the function to be called when the regulator is invoked. * @param func * @returns > */ onProcess(func: (...args: T) => Promise): RegulatorOf; /** * @remarks * Invoke the regulator with the given arguments. * @param args * @returns > */ invoke(...args: T): Promise; /** * @remarks * Invoke the regulator with the given arguments. * This will call the function with the given arguments and return a promise that resolves when all functions are done. * Note that order of the results is not same as the order of the arguments. * @param items */ invokeAll(items: T[]): Promise[]; } /** * @remarks * Get a regulator that allows you to regulate the number of concurrent processes. * @param name * @returns > */ export declare const Regulator: { /** * Get a regulator * @param name * @returns > */ of: (name: string) => RegulatorOf; };