Skip to content

Commit

Permalink
fix for race condition in issue postwait#135
Browse files Browse the repository at this point in the history
  • Loading branch information
lookfirst committed Feb 10, 2013
1 parent 127a4ca commit 49f362b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions amqp.js
Expand Up @@ -2231,16 +2231,18 @@ Exchange.prototype.publish = function (routingKey, data, options, callback) {
self.connection._sendBody(self.channel, data, options);
});

if (self.options.confirm){
if (self.options.confirm) {
task.sequence = self._sequence
self._unAcked[self._sequence] = task
self._sequence++

if(callback != null){
var errorCallback = function(){task.removeAllListeners();callback(true)};
var exchange = this;
task.once('ack', function(){exchange.removeListener('error', errorCallback); task.removeAllListeners();callback(false)});
this.once('error', errorCallback);
if (callback != null) {
var errorCallback = function(){task.removeAllListeners(); self.hasErrorListener=false; callback(true)};
task.once('ack', function(){self.removeListener('error', errorCallback); self.hasErrorListener=false; task.removeAllListeners(); callback(false)});
if (!this.hasErrorListener) {
this.once('error', errorCallback);
this.hasErrorListener = true;
}
}
}

Expand Down

0 comments on commit 49f362b

Please sign in to comment.