Skip to content

Commit

Permalink
Moving event bindings to newSession/newConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
noodlefrenzy committed Aug 7, 2015
1 parent 2b1da82 commit f413b72
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions lib/amqp_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,6 @@ AMQPClient.prototype.connect = function(url) {
self._session.connection = self._connection;
} else {
self._session = self._newSession(c);
self._session.on(Session.Unmapped, function(s) {
debug('unmapped');
});

self._session.on(Session.ErrorReceived, function(e) {
debug('session error: ', e);
self.emit(AMQPClient.ErrorReceived, e);
});
}

self._session.on(Session.Mapped, function(s) {
Expand Down Expand Up @@ -172,11 +164,6 @@ AMQPClient.prototype.connect = function(url) {
}, self._timeouts.shift());
});

self._connection.on(Connection.ErrorReceived, function(e) {
debug('connection error: ', e);
self.emit(AMQPClient.ErrorReceived, e);
});

self._connection.open(address, sasl);
});
};
Expand Down Expand Up @@ -337,11 +324,29 @@ AMQPClient.prototype._clearConnectionState = function(saveReconnectDetails) {

// Helper methods for mocking in tests.
AMQPClient.prototype._newConnection = function() {
return new Connection(this.policy.connect);
var self = this;
var connection = new Connection(this.policy.connect);
connection.on(Connection.ErrorReceived, function(e) {
debug('connection error: ', e);
self.emit(AMQPClient.ErrorReceived, e);
});

return connection;
};

AMQPClient.prototype._newSession = function(conn) {
return new Session(conn);
var self = this;
var session = new Session(conn);
session.on(Session.Unmapped, function(s) {
debug('unmapped');
});

session.on(Session.ErrorReceived, function(e) {
debug('session error: ', e);
self.emit(AMQPClient.ErrorReceived, e);
});

return session;
};

AMQPClient.prototype._preventReconnect = function() {
Expand Down

0 comments on commit f413b72

Please sign in to comment.