tianji-client-sdk
Version:
61 lines • 1.54 kB
TypeScript
/**
* Generic Batch Manager for request batching
* Provides throttling and automatic batch sending functionality
*/
export interface BatchItem<T = any> {
type: string;
payload: T;
}
export interface BatchManagerOptions {
/**
* Batch delay in milliseconds (defaults to 200ms)
*/
batchDelay?: number;
/**
* Maximum batch size before auto-flush (defaults to 100)
*/
maxBatchSize?: number;
/**
* Disable batch mode and send requests immediately (defaults to false)
*/
disableBatch?: boolean;
/**
* Callback to send batch request
*/
onBatchSend: (items: BatchItem[]) => Promise<void>;
/**
* Callback to send single request (used when batch is disabled)
*/
onSingleSend: (item: BatchItem) => Promise<void>;
}
export declare class BatchManager<T = any> {
private queue;
private timer;
private options;
constructor(options: BatchManagerOptions);
/**
* Add item to batch queue
*/
add(type: string, payload: T): void;
/**
* Send batch request
*/
private sendBatch;
/**
* Flush batch queue manually (send all pending requests immediately)
*/
flush(): Promise<void>;
/**
* Clear batch queue without sending
*/
clear(): void;
/**
* Update batch manager options
*/
updateOptions(options: Partial<BatchManagerOptions>): void;
/**
* Get current queue size
*/
getQueueSize(): number;
}
//# sourceMappingURL=batch-manager.d.ts.map