Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
rhea.once("connection_open", connection_open);
// register an event handler for if the connection fails to open
rhea.once("disconnected", disconnected);
// attempt the connection
this.connection = rhea.connect(c);
}.bind(this)
);
// 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
rhea.once('connection_open', connection_open);
// register an event handler for if the connection fails to open
rhea.once('disconnected', disconnected);
// attempt the connection
this.connection = rhea.connect(c);
}).bind(this));
}
// 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
rhea.once('connection_open', connection_open);
// register an event handler for if the connection fails to open
rhea.once('disconnected', disconnected);
// attempt the connection
this.connection = rhea.connect(c);
}).bind(this));
}
return new Promise((resolve, reject) => {
container.once('connection_error', (err: any) => reject(err.error));
container.once('error', (err: any) => reject(err.error));
container.once('sender_error', (err: any) => reject(err.error));
container.once('disconnected', (err: any) => reject(err.error));
container.once('rejected', (err: any) => reject(err.error));
container.once('connection_open', (context: any) => {
context.connection.open_sender(this.options);
});
container.once('sendable', (context: any) => {
const delivery = context.sender.send(this.payload);
this.messageReceived = new ObjectDecycler().decycle(delivery);
context.sender.detach();
resolve();
});
container.connect(this.connection);
});
}
return new Promise((resolve, reject) => {
container.once('message', (context: any) => {
resolve(context.message);
context.connection.close();
});
container.once('error', reject);
});
}
private registerFailures(reject: any) {
container.once('connection_close', (err: any) => this.rejectCallback('connection_close', err, reject));
container.once('connection_error', (err: any) => this.rejectCallback('connection_error', err, reject));
container.once('error', (err: any) => this.rejectCallback('error', err, reject));
container.once('receiver_close', (err: any) => this.rejectCallback('receiver_close', err, reject));
}
private registerFailures(reject: any) {
container.once('connection_close', (err: any) => this.rejectCallback('connection_close', err, reject));
container.once('connection_error', (err: any) => this.rejectCallback('connection_error', err, reject));
container.once('error', (err: any) => this.rejectCallback('error', err, reject));
container.once('receiver_close', (err: any) => this.rejectCallback('receiver_close', err, reject));
}
return new Promise((resolve, reject) => {
this.registerFailures(reject);
if (this.server === true) {
const server = container.listen(this.connection);
server.once('listening', resolve);
server.once('connection', server.close);
server.once('error', (err: any) => reject(err.error));
} else {
container.connect(this.connection);
this.removeFailure();
}
container.once('connection_open', (context: any) => {
Logger.info(`${this.type} connection opened`);
this.removeFailure();
context.connection.open_receiver(this.options);
resolve();
});
});
}
return new Promise((resolve, reject) => {
container.once('connection_error', (err: any) => reject(err.error));
container.once('error', (err: any) => reject(err.error));
container.once('sender_error', (err: any) => reject(err.error));
container.once('disconnected', (err: any) => reject(err.error));
container.once('rejected', (err: any) => reject(err.error));
container.once('connection_open', (context: any) => {
context.connection.open_sender(this.options);
});
container.once('sendable', (context: any) => {
const delivery = context.sender.send(this.payload);
this.messageReceived = new ObjectDecycler().decycle(delivery);
context.sender.detach();
resolve();
});
container.connect(this.connection);
});
}
return new Promise((resolve, reject) => {
container.once('message', (context: any) => {
resolve(context.message);
context.connection.close();
});
container.once('error', reject);
});
}