import { QueueDataType, DispatcherOptionsType, DispatcherStorageType, ResolvedQueueDataType, ResolvedQueueItemType, RunningRequestValueType } from '.'; import { ClientInstance } from '../client'; import { EventEmitter } from '../utils'; import { RequestInstance } from '../request'; import { AdapterInstance } from '../adapter'; /** * Dispatcher controls and manages the requests that are going to be executed with adapter. It manages them based on the options provided with request. * This class can also run them with different modes like deduplication, cancelation, queueing or run-all-at-once mode. With it's help we can pause, * stop, start and cancel requests. */ export declare class Dispatcher { options?: DispatcherOptionsType | undefined; emitter: EventEmitter; events: { emitDrained: (values: QueueDataType, isTriggeredExternally?: boolean) => void; emitQueueStatusChanged: (values: QueueDataType, isTriggeredExternally?: boolean) => void; emitQueueChanged: (values: QueueDataType, isTriggeredExternally?: boolean) => void; onDrained: (callback: (values: QueueDataType) => void) => VoidFunction; onDrainedByKey: (queryKey: string, callback: (values: QueueDataType) => void) => VoidFunction; onQueueStatusChange: (callback: (values: QueueDataType) => void) => VoidFunction; onQueueStatusChangeByKey: (queryKey: string, callback: (values: QueueDataType) => void) => VoidFunction; onQueueChange: (callback: (values: QueueDataType) => void) => VoidFunction; onQueueChangeByKey: (queryKey: string, callback: (values: QueueDataType) => void) => VoidFunction; }; storage: DispatcherStorageType; private requestCount; private runningRequests; private logger; private client; constructor(options?: DispatcherOptionsType | undefined); private isRequestJSON; initialize: (client: ClientInstance<{ adapter: Adapter; }>) => this; /** * Start request handling by queryKey */ start: (queryKey: string) => void; /** * Pause request queue, but do not cancel already started requests */ pause: (queryKey: string) => void; /** * Stop request queue and cancel all started requests - those will be treated like not started */ stop: (queryKey: string) => void; /** * Return all */ getQueuesKeys: () => string[]; /** * Return queue state object. * Automatically reconstructs any serialized (JSON) requests back into * proper Request class instances so the rest of the pipeline can rely on * having a real `RequestInstance`. */ getQueue: (queryKey: string) => ResolvedQueueDataType; /** * Return request from queue state */ getRequest: (queryKey: string, requestId: string) => import('.').QueueItemType | undefined; /** * Get value of the active queue status based on the stopped status */ getIsActiveQueue: (queryKey: string) => boolean; /** * Add new element to storage */ addQueueItem: (queryKey: string, element: ResolvedQueueItemType) => void; /** * Set new queue storage value */ setQueue: (queryKey: string, queue: ResolvedQueueDataType) => ResolvedQueueDataType; /** * Clear requests from queue cache */ clearQueue: (queryKey: string) => { queryKey: string; requests: never[]; stopped: boolean; }; /** * Method used to flush the queue requests */ flushQueue: (queryKey: string) => Promise; /** * Flush all available requests from all queues */ flush: () => Promise; /** * Clear all running requests and storage */ clear: () => void; /** * Start particular request */ startRequest: (queryKey: string, requestId: string) => void; /** * Stop particular request */ stopRequest: (queryKey: string, requestId: string) => void; /** * Get currently running requests from all queryKeys */ getAllRunningRequests: () => RunningRequestValueType[]; /** * Get currently running requests */ getRunningRequests: (queryKey: string) => RunningRequestValueType[]; /** * Get running request by id */ getRunningRequest: (queryKey: string, requestId: string) => RunningRequestValueType | undefined; /** * Add request to the running requests list */ addRunningRequest: (queryKey: string, requestId: string, request: RequestInstance) => RunningRequestValueType; /** * Get the value based on the currently running requests */ hasRunningRequests: (queryKey: string) => boolean; /** * Check if request is currently processing */ hasRunningRequest: (queryKey: string, requestId: string) => boolean; /** * Cancel all started requests, but do NOT remove it from main storage */ cancelRunningRequests: (queryKey: string) => void; /** * Cancel started request, but do NOT remove it from main storage */ cancelRunningRequest: (queryKey: string, requestId: string) => void; /** * Delete all started requests, but do NOT clear it from queue and do NOT cancel them */ deleteRunningRequests: (queryKey: string) => void; /** * Delete request by id, but do NOT clear it from queue and do NOT cancel them */ deleteRunningRequest: (queryKey: string, requestId: string) => void; /** * Get count of requests from the same queryKey */ getQueueRequestCount: (queryKey: string) => number; /** * Add request count to the queryKey */ incrementQueueRequestCount: (queryKey: string) => void; /** * Create storage element from request */ createStorageItem: (request: R) => ResolvedQueueItemType; /** * Add request to the dispatcher handler */ add: (request: RequestInstance) => string; /** * Delete from the storage and cancel request */ delete: (queryKey: string, requestId: string, abortKey: string) => ResolvedQueueDataType | undefined; /** * Request can run for some time, once it's done, we have to check if it's successful or if it was aborted * It can be different once the previous call was set as cancelled and removed from queue before this request got resolved */ performRequest: (storageItem: ResolvedQueueItemType) => Promise>; } //# sourceMappingURL=dispatcher.d.ts.map