-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
dispatcher.types.ts
39 lines (34 loc) · 1.31 KB
/
dispatcher.types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Dispatcher } from "dispatcher";
import { RequestInstance } from "request";
export type DispatcherOptionsType = {
storage?: DispatcherStorageType;
onInitialization?: (dispatcherInstance: Dispatcher) => void;
onUpdateStorage?: <Request extends RequestInstance>(queueKey: string, data: QueueDataType<Request>) => void;
onDeleteFromStorage?: <Request extends RequestInstance>(queueKey: string, data: QueueDataType<Request>) => void;
onClearStorage?: (dispatcherInstance: Dispatcher) => void;
};
// Values
export type QueueElementType<Request extends RequestInstance = RequestInstance> = {
requestId: string;
request: Request;
retries: number;
timestamp: number;
stopped: boolean;
};
export type QueueDataType<Request extends RequestInstance = RequestInstance> = {
requests: QueueElementType<Request>[];
stopped: boolean;
};
// Storage
export type DispatcherStorageType = {
set: <Request extends RequestInstance = RequestInstance>(key: string, data: QueueDataType<Request>) => void;
get: <Request extends RequestInstance = RequestInstance>(key: string) => QueueDataType<Request> | undefined;
keys: () => string[] | IterableIterator<string>;
delete: (key: string) => void;
clear: () => void;
};
// Running
export type RunningRequestValueType = {
requestId: string;
request: RequestInstance;
};