vertex
Version:
distributed pub/sub using hash rings
32 lines (24 loc) • 596 B
JavaScript
module.exports = class Sockets {
static get dependants() { return ['cluster', 'tcp']; }
constructor(server, logger, config) {
this.logger = logger;
this.sockets = [];
}
async start() {}
async stop() {
this.logger.info('stopping');
this.sockets.forEach(socket => {
socket.end();
});
this.sockets.length = 0;
}
add(socket) {
socket.on('close', () => this.remove(socket));
this.sockets.push(socket);
}
remove(socket) {
var offset = this.sockets.indexOf(socket);
if (offset < 0) return;
this.sockets.splice(offset, 1);
}
}