rabbitmq-tutorials/javascript-nodejs/amqp-hacks.js
2012-04-17 17:05:17 +01:00

19 lines
498 B
JavaScript

exports.safeEndConnection = function(connection) {
// `connection.end` doesn't flush outgoing buffers, run a
// synchronous command to comprehend
connection.queue('tmp-' + Math.random(), {exclusive: true}, function(){
connection.end();
// `connection.end` in 0.1.3 raises a ECONNRESET error, silence it:
connection.once('error', function(e){
if (e.code !== 'ECONNRESET' || e.syscall !== 'write')
throw e;
});
});
};