Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var connection_open = function (context) {
clearTimeout(timer);
// prevent future disconnects from calling reject
rhea.removeListener("disconnected", disconnected);
// we were just checking. we don't really want a connection
if (options.test) {
context.connection.close();
this.connection = null;
} else this.on_connection_open();
var res = { context: context };
if (callback) callback(res);
resolve(res);
}.bind(this);
// register an event handler for when the connection opens
var disconnected = function () {
clearTimeout(timer);
rhea.removeListener("disconnected", disconnected);
rhea.removeListener("connection_open", connection_open);
this.connection = null;
var rej = "failed to connect";
if (callback) callback({ error: rej });
reject(Error(rej));
}.bind(this);
var timer = setTimeout(disconnected, timeout);
var disconnected = (function () {
clearTimeout(timer);
rhea.removeListener('disconnected', disconnected);
rhea.removeListener('connection_open', connection_open);
this.connection = null;
var rej = 'failed to connect';
if (callback)
callback({ error: rej });
reject(Error(rej));
}).bind(this);
var timer = setTimeout(disconnected, timeout);
var disconnected = (function () {
clearTimeout(timer);
rhea.removeListener('disconnected', disconnected);
rhea.removeListener('connection_open', connection_open);
this.connection = null;
var rej = 'failed to connect';
if (callback)
callback({ error: rej });
reject(Error(rej));
}).bind(this);
var timer = setTimeout(disconnected, timeout);