relay-link-batch
Version:
Relay Link that performs batching and operation on batched Operations
28 lines • 1.25 kB
TypeScript
import { Operation, NextLink, OperationResponse } from 'relay-link';
import { Observable } from 'relay-runtime';
export declare type BatchHandler = (operations: Operation[], forward?: (NextLink | undefined)[]) => Observable<OperationResponse[]>;
export interface BatchableRequest {
operation: Operation;
forward?: NextLink;
observable?: Observable<OperationResponse>;
next?: Array<(result: OperationResponse) => void>;
error?: Array<(error: Error) => void>;
complete?: Array<() => void>;
}
export declare class OperationBatcher {
readonly queuedRequests: Map<string, BatchableRequest[]>;
private readonly batchInterval?;
private readonly batchMax;
private readonly batchHandler;
private readonly batchKey;
constructor({ batchInterval, batchMax, batchHandler, batchKey, }: {
batchInterval?: number;
batchMax?: number;
batchHandler: BatchHandler;
batchKey?: (operation: Operation) => string;
});
enqueueRequest(request: BatchableRequest): Observable<OperationResponse>;
consumeQueue(key?: string): (Observable<OperationResponse> | undefined)[] | undefined;
private scheduleQueueConsumption;
}
//# sourceMappingURL=batching.d.ts.map