Skip to content

Commit

Permalink
[fix] handle multiple queues
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrugzz committed Jun 8, 2015
1 parent b67b601 commit e9db410
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Socket (rabbit, options) {
this.channel = undefined;

this.ready = false;
this._deferredConnection = false;
this._deferredConnections = [];

if(!this.rabbit.ready) {
this.rabbit.once('ready', this._setup.bind(this));
Expand All @@ -32,8 +32,13 @@ Socket.prototype._setup = function (channel) {
this._setChannel(channel);
this.ready = true;
this.emit('ready');
if (this._deferredConnection) {
var queueName = this._deferredConnection.queueName;
if (!this._deferredConnections.length) return;

//
// Connect to call queues that were deferred
//
for (var i = 0; i < this._deferredConnections.length; i++){
var queueName = this._deferredConnections[i].queueName;
return void this.connect(queueName);
}
};
Expand Down Expand Up @@ -89,7 +94,7 @@ function RepSocket() {

RepSocket.prototype.connect = function (source) {
if (!this.ready) {
this._deferredConnection = { queueName: source };
this._deferredConnections.push({ queueName: source });
return this;
}

Expand Down Expand Up @@ -224,7 +229,7 @@ ReqSocket.prototype._handleReceipt = function (msg) {

ReqSocket.prototype.connect = function (destination) {
if (!this.ready) {
this._deferredConnection = { queueName: destination };
this._deferredConnections.push({ queueName: destination });
return this;
}
var self = this;
Expand Down

0 comments on commit e9db410

Please sign in to comment.