-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
dispatcher.types.ts
39 lines (34 loc) · 1.36 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 { CommandDump, CommandInstance } from "command";
export type DispatcherOptionsType = {
storage?: DispatcherStorageType;
onInitialization?: (dispatcherInstance: Dispatcher) => void;
onUpdateStorage?: <Command extends CommandInstance>(queueKey: string, data: DispatcherData<Command>) => void;
onDeleteFromStorage?: <Command extends CommandInstance>(queueKey: string, data: DispatcherData<Command>) => void;
onClearStorage?: (dispatcherInstance: Dispatcher) => void;
};
// Values
export type DispatcherDumpValueType<Command extends CommandInstance = CommandInstance> = {
requestId: string;
commandDump: CommandDump<Command>;
retries: number;
timestamp: number;
stopped: boolean;
};
export type DispatcherData<Command extends CommandInstance = CommandInstance> = {
requests: DispatcherDumpValueType<Command>[];
stopped: boolean;
};
// Storage
export type DispatcherStorageType = {
set: <Command extends CommandInstance = CommandInstance>(key: string, data: DispatcherData<Command>) => void;
get: <Command extends CommandInstance = CommandInstance>(key: string) => DispatcherData<Command> | undefined;
keys: () => string[] | IterableIterator<string>;
delete: (key: string) => void;
clear: () => void;
};
// Running
export type RunningRequestValueType = {
requestId: string;
command: CommandInstance;
};