diff --git a/.npmignore b/.npmignore index 356d590e..4ec93971 100644 --- a/.npmignore +++ b/.npmignore @@ -4,6 +4,5 @@ scratch # node_modules is ignored anyway .travis.yml bin/amqp-rabbitmq-0.9.1.json -bin/generate-defs.js etc/ coverage/ diff --git a/lib/channel.js b/lib/channel.js index d2b8786b..fc8f17d6 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -33,6 +33,12 @@ function Channel(connection) { this.on('nack', this.handleConfirm.bind(this, function(cb) { if (cb) cb(new Error('message nacked')); })); + this.on('close', function () { + var cb; + while (cb = this.unconfirmed.shift()) { + if (cb) cb(new Error('channel closed')); + } + }) // message frame state machine this.handleMessage = acceptDeliveryOrReturn; } diff --git a/package.json b/package.json index 2c92fcb7..d9707dd3 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ }, "scripts": { "test": "make test", - "prepublish": "make" + "prepare": "make" }, "keywords": [ "AMQP", diff --git a/test/channel_api.js b/test/channel_api.js index 99c9f9c4..bd5473f0 100644 --- a/test/channel_api.js +++ b/test/channel_api.js @@ -581,4 +581,17 @@ confirmtest('wait for confirms', function(ch) { return ch.waitForConfirms(); }) +confirmtest('works when channel is closed', function(ch) { + for (var i=0; i < 1000; i++) { + ch.publish('', '', Buffer.from('foobar'), {}); + } + return ch.close().then(function () { + return ch.waitForConfirms() + }).then(function () { + assert.strictEqual(true, false, 'Wait should have failed.') + }, function (e) { + assert.strictEqual(e.message, 'channel closed') + }); +}); + });