1
0
forked from keinBot/cuffeo

moar async

This commit is contained in:
Flummi
2019-08-20 21:53:43 +00:00
parent b6d3212828
commit d0821b3553
2 changed files with 58 additions and 69 deletions

View File

@@ -12,8 +12,8 @@ export default class cuffeo extends EventEmitter {
this.libs = {};
return (async () => {
this.libs = await this.loadLibs();
this.clients = this.registerClients(cfg);
this.libs = await this.loadLibs();
this.clients = await this.registerClients(cfg);
return this;
})();
}
@@ -25,16 +25,18 @@ export default class cuffeo extends EventEmitter {
}
return _libs;
}
registerClients(cfg) {
return cfg.filter(e => e.enabled).map(srv => {
async registerClients(cfg) {
return cfg.filter(e => e.enabled).map(async srv => {
if(!Object.keys(this.libs).includes(srv.type))
throw new Error(`not supported client: ${srv.type}`);
return {
const client = {
name: srv.network,
type: srv.type,
client: new this.libs[srv.type](srv)
client: await new this.libs[srv.type](srv)
};
client.client.on("data", ([type, data]) => this.emit(type, data));
return client;
});
}
};