forked from InteractiveAdvertisingBureau/iabtcf-es
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventListenerQueue.ts
More file actions
52 lines (31 loc) · 1018 Bytes
/
EventListenerQueue.ts
File metadata and controls
52 lines (31 loc) · 1018 Bytes
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
40
41
42
43
44
45
46
47
48
49
50
51
52
import {GetTCDataCommand} from './command/GetTCDataCommand.js';
import {CommandCallback} from './command/CommandCallback.js';
interface EventItem {
callback: CommandCallback;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
param?: any;
next?: CommandCallback;
}
export class EventListenerQueue {
private eventQueue = new Map<number, EventItem>();
private queueNumber = 0;
public add(eventItems: EventItem): number {
this.eventQueue.set(this.queueNumber, eventItems);
return this.queueNumber++;
}
public remove(listenerId: number): boolean {
return this.eventQueue.delete(listenerId);
}
public exec(): void {
this.eventQueue.forEach((eventItem: EventItem, listenerId: number): void => {
new GetTCDataCommand(eventItem.callback, eventItem.param, listenerId, eventItem.next);
});
}
public clear(): void {
this.queueNumber = 0;
this.eventQueue.clear();
}
public get size(): number {
return this.eventQueue.size;
}
}