2020-09-28 21:36:32 +02:00
|
|
|
const { listen } = require('../ws/db');
|
2021-05-24 13:48:53 +02:00
|
|
|
const channels = require('../lib/db/channels');
|
|
|
|
|
const handlers = require('./handlers').init();
|
2020-09-28 21:36:32 +02:00
|
|
|
|
|
|
|
|
function start () {
|
2021-05-24 13:48:53 +02:00
|
|
|
listen(channels, async function (data) {
|
|
|
|
|
for (const handler of handlers) {
|
|
|
|
|
// NOTE: We are intentionally passing the same instance
|
|
|
|
|
// of the data to every handler. This means that earlier
|
|
|
|
|
// handlers could, in principle, modify the data to be
|
|
|
|
|
// consumed by latter ones, provided that they are
|
|
|
|
|
// synchronous (as otherwise, the completion order is
|
|
|
|
|
// undefined).
|
|
|
|
|
await handler.run(data);
|
2020-09-28 21:36:32 +02:00
|
|
|
}
|
|
|
|
|
});
|
2022-04-29 14:48:21 +02:00
|
|
|
|
2021-05-24 13:48:53 +02:00
|
|
|
console.log("Events manager started.", handlers.length, "active handlers");
|
2020-09-28 21:36:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = { start }
|
2020-10-02 01:34:49 +02:00
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
|
start();
|
|
|
|
|
}
|