Skip to content

Commit

Permalink
feat(connected-disconnected): add signals for connection state
Browse files Browse the repository at this point in the history
This is a stopgap before a full event overhaul for a 4.x release
of this module. These event names will not change (thus do not
need a major push), but where they are emitted from might be
subject to change in the future
  • Loading branch information
mbroadst committed Jun 22, 2016
1 parent 7aa450f commit 4f8d4ff
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/amqp_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ AMQPClient.prototype.connect = function(url) {

self._session.once(Session.Mapped, function(s) {
debug('mapped');
self.emit('connected');
resolve(self);
});

Expand All @@ -128,6 +129,7 @@ AMQPClient.prototype.connect = function(url) {

self._connection.on(Connection.Disconnected, function() {
debug('disconnected');
self.emit('disconnected');
self.emit(AMQPClient.ConnectionClosed);
if (!self._shouldReconnect()) {
self._clearConnectionState(false);
Expand Down Expand Up @@ -301,11 +303,13 @@ AMQPClient.prototype.disconnect = function() {
self._clearConnectionState();
connection.once(Connection.Disconnected, function() {
debug('disconnected');
self.emit('disconnected');
connection = undefined;
resolve();
});
connection.close();
} else {
self.emit('disconnected');
resolve(); // Already disconnected, just deliver the promise.
}
});
Expand Down

0 comments on commit 4f8d4ff

Please sign in to comment.