-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
42 lines (38 loc) · 1.12 KB
/
main.js
File metadata and controls
42 lines (38 loc) · 1.12 KB
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
const Observable = require('rxjs')
const { concatMap } = require('rxjs/operators')
const ZeroMqReader = require('./readers/zeromq')
const LoggerHandler = require('./handlers/logger')
const MongoDbHandler = require('./handlers/mongodb')
const WebsocketHandler = require('./handlers/websocket')
main().catch(error => {
console.error(error)
process.exit(1)
})
async function main() {
// Instantiate reader and handlers
const reader = new ZeroMqReader()
const loggerHandler = new LoggerHandler(['COMMIT'])
// const dbHandler = new MongoDbHandler()
// const wsHandler = new WebsocketHandler()
// Connect them together
// (using a queue for async operations from concatMap)
Observable.fromEvent(reader, 'operation')
.pipe(
concatMap(op =>
Promise.all([
loggerHandler.handle(op)
// dbHandler.handle(op),
// wsHandler.handle(op)
])
)
)
.subscribe()
// Start the handlers first
await Promise.all([
loggerHandler.start()
// dbHandler.start(),
// wsHandler.start()
])
// And then the reader once everything is ready
await reader.start()
}