UNPKG

node-apparatus

Version:

A mix of common components needed for awesome node experience

29 lines (28 loc) 1.43 kB
import { Serializable } from "../sequential-invocation-queue/sequential-invocation-queue.js"; import { IAccumulator } from "./i-accumulator.js"; /** * A distributed window implementation that can be used to accumulate elements and drain them in a window of specific size. */ export declare class DistributedWindow<T extends Serializable> { private readonly windowSize; private readonly distributedAccumulator; /** * Creates a new instance of DistributedWindow. * @param windowSize The size of the window. Should be more greater than 0. * @param distributedAccumulator The distributed accumulator to accumulate elements. * @throws Error if windowSize is less than or equal to 0. */ constructor(windowSize: number, distributedAccumulator: IAccumulator<T>); /** * Accumulates a new element and returns the window if the window is full. * @param element The new element to be accumulated. * @returns The window if the window size is met , otherwise undefined. It can return multiple windows if the previous windows are not drained. * @remarks The sequence of elements can change if the drain implementation returns elements not in the multiple of window size. */ window(element: T): Promise<T[][] | undefined>; /** * Flushes all elements from the accumulator and returns the windows. * @returns The windows. */ flush(): Promise<T[][]>; }