forked from PerryTS/perry
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_minimal_demo.ts
More file actions
46 lines (37 loc) · 930 Bytes
/
test_minimal_demo.ts
File metadata and controls
46 lines (37 loc) · 930 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
import { EventEmitter } from 'events';
interface ProcessedEvent {
network: string;
timestamp: number;
}
class Connection extends EventEmitter {
private network: string;
constructor(network: string) {
super();
this.network = network;
}
public connect(): void {
const event: ProcessedEvent = {
network: this.network,
timestamp: Date.now()
};
this.emit('event', event);
}
}
class Manager extends EventEmitter {
public initialize(): void {
const networks = ['ethereum', 'polygon'];
for (const network of networks) {
const connection = new Connection(network);
connection.on('event', (event: ProcessedEvent) => {
this.emit('event', event);
});
connection.connect();
}
}
}
const manager = new Manager();
manager.on('event', (event: ProcessedEvent) => {
console.log("Received event");
});
manager.initialize();
console.log("Done");