Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async init () {
await super.init()
super.$pushDestructor(() => {
this._clients = null
this._awaitBind = null
this._socket.close()
this._socket = null
clearInterval(this._pruneClientsTimer)
})
this._awaitBind = new Map()
this._clients = new Map()
this._socket = zmq.socket('router')
this._socket.setsockopt(zmq.options.identity, msg.SRV_ID)
this._socket.on('message', (...args) => {
this._handleMessage(...args)
})
this._socket.on('error', (...args) => {
console.error(args)
process.exit(1)
})
this._socket.on('bind', b => {
this._handleBind(b, this._socket.last_endpoint)
})
this._pruneClientsTimer = setInterval(() => {
this._pruneClients()
}, 1500)
}
this._startPromise = new Promise((resolve, reject) => {
const toBind = {}
const bindTimeout = setTimeout(() => {
reject(new Error('timeout binding to: ' + Object.keys(toBind)))
}, 1000)
this._socket = zmq.socket('router')
this._socket.setsockopt(zmq.options.identity, common.SRV_ID)
this._socket.on('message', (...args) => {
this._handleMessage(...args)
})
this._socket.on('error', (...args) => {
console.error(args)
process.exit(1)
})
this._socket.on('bind', (binding) => {
delete toBind[binding]
if (Object.keys(toBind).length < 1) {
clearTimeout(bindTimeout)
resolve()
}
})
for (let b of bind) {
MultiplexingSocket.prototype.close = function(linger) {
if (this.closed()) {
throw Error("Socket already closed");
}
if (linger !== undefined) {
this._zmqSocket.setsockopt(zmq.options.linger, linger);
}
this._zmqSocket.close();
for(var id in this.channels) this.channels[id].destroy();
this._closed = true;
};