Expand description
interface BatchConstructor<TFn extends AnyFn> {
batch: (args: Parameters<TFn>[]) => Parameters<TFn>;
disregardExecutionTime?: boolean;
fn: TFn;
interval: number;
unbatch?: (
inputs: Parameters<TFn>[],
output: AwaitRet<TFn>,
) => AwaitRet<TFn>[];
}Properties§
§§§§§
batch: { ... }Function to batch the inputs across multiple calls
disregard Execution Time?: booleanSee debounce for more information
fn: TFnFunction to be wrapped
interval: numberInterval between each batched call
unbatch?: { ... }If provided, unbatch the output according to the inputs, so each call receives its own output.
By default, each input will receive the same output from the batched call
Options to construct a
batchfunctionA batch function is an async event wrapper that allows multiple calls in an interval to be batched together, and only call the underlying function once.
Optionally, the output can be unbatched to match the inputs.
Example
The API is a lot like
debounce, but with an additionalbatchfunction and an optionalunbatchfunction.Unbatching
The optional
unbatchfunction allows the output to be unbatched, so the promises are resolved as if the underlying function is called directly.Note that unbatching is usually slow and not required.