import { type Inbox, type InboxStateDetail } from "./Inbox.ts"; export declare enum ClerkState { IDLE = "idle", DISPOSED = "disposed", WORKING = "working", STALLED = "not-started" } export type ClerkOptionBase = { name?: string; assigned: Inbox; }; export type ClerkOption = ClerkOptionBase & { job: (item: T) => Promise | any; }; export type ClerkGroupOption> = ClerkOptionBase & { job: (item: T) => Promise | any; instantiate: (params: ClerkOption) => U; initialMemberCount: number; }; export declare const SENTINEL_FINISHED: unique symbol; export declare const SENTINEL_FLUSH: unique symbol; export type SENTINELS = typeof SENTINEL_FINISHED | typeof SENTINEL_FLUSH; type FeederStateDetail = { hasStarted: boolean; hasFinished: boolean; totalFetched: number; totalProcessed: number; }; type ClerkStateDetail = { inboxDetail: InboxStateDetail; totalFetched: number; totalProcessed: number; isBusy: boolean; hasStarted: boolean; state: ClerkState; }; export declare abstract class ClerkBase { _inbox: Inbox; _name: string; abstract _onPick(item: T): Promise; _onSentinel?(item: SENTINELS): Promise; _state: ClerkState; _totalProcessed: number; _totalSuccess: number; _totalFailed: number; _totalFetched: number; _disposed: boolean; _disposePromise: { promise: Promise; resolve: (value: void | PromiseLike) => void; reject: (reason?: any) => void; }; get state(): ClerkState; constructor(params: ClerkOptionBase); get stateDetail(): ClerkStateDetail; _onProgress?: (state: ClerkStateDetail) => void; onProgress(): void; setOnProgress(callback: (state: ClerkStateDetail) => void): void; _mainLoop(): Promise; dispose(): void; get onDisposed(): Promise; } export declare class Clerk extends ClerkBase { _onPick(item: T): Promise; _job: (item: T) => Promise; constructor(params: ClerkOption); } export declare class ClerkGroup> { _clerks: U[]; _nameBase: string; _assigned: Inbox; _hiredCount: number; _job: (item: T) => Promise; _instantiate: (params: ClerkOption) => U; constructor(params: ClerkGroupOption); hireMember(params: ClerkOption): void; fireMember(): void; adjustMemberCount(count: number): void; get stateDetail(): ClerkStateDetail; get freeMembers(): number; dispose(): void; } /** * A clerk that making batch of items and posts that to another inbox. * Please keep in mind that the interval of consuming results should be realised by `PaceMaker`. * @template T - The type of items being processed. * @property {ClerkStateDetail} stateDetail - Returns the current state details. */ export declare class Porter extends ClerkBase { _outgoing: Inbox; _timeout?: number; _maxSize: number; _buffer: T[]; _timeoutTimer: ReturnType | undefined; _flushing: Promise; _separateChunk: boolean; _flush(): Promise; get stateDetail(): ClerkStateDetail; _onSentinel(item: SENTINELS): Promise; _onPick(item: T): Promise; flush(): Promise; changeParams(params: { timeout?: number; maxSize?: number; }): Promise; constructor(params: { from: Inbox; to: Inbox; timeout?: number; maxSize: number; }); dispose(): void; } /** * The `Feeder` class is responsible for fetching items from a source and posting them to a target inbox. * It supports both synchronous and asynchronous iteration over the source. * * @template T - The type of items being processed. * * @property {FeederStateDetail} stateDetail - Returns the current state details of the feeder. * @property onProgress - Calls the progress callback with the current state details. * @property setOnProgress - Sets the progress callback function. * * @property _mainLoop - The main loop that fetches items from the source and posts them to the target. * @property stateDetail - Returns the current state details of the feeder. */ export declare class Feeder { _hasFinished: boolean; _hasStarted: boolean; _totalFetched: number; _totalProcessed: number; _source: Iterable | AsyncIterable; _target: Inbox; _onProgress?: (state: FeederStateDetail) => void; onProgress(): void; setOnProgress(callback: (state: FeederStateDetail) => void): void; /** * * @param {Object} params - The parameters for the feeder. * @param {Iterable | AsyncIterable} params.source - The source of items to be processed. * @param {Inbox} params.target - The target inbox where items are posted. * @param {(state: FeederStateDetail) => void} [params.onProgress] - Optional callback function to report progress. */ constructor(params: { source: Iterable | AsyncIterable; target: Inbox; onProgress?: (state: FeederStateDetail) => void; }); _mainLoop(): Promise; get stateDetail(): FeederStateDetail; } /** * a clerk that picks items from an inbox and stores them in a buffer. * @template T - The type of items being processed. * @property {T[]} result - Returns the buffer of items. * @property clear - Clears the buffer. * @property drainAndReset - Drains the buffer and resets it. */ export declare class Harvester extends ClerkBase { _buffer: T[]; _timeoutTimer: ReturnType | undefined; get result(): T[]; clear(): void; drainAndReset(): T[]; _onPick(item: T): Promise; constructor(params: ClerkOptionBase); dispose(): void; } export {};