From d80b873a6ee7cc5c1272454b183af953737d3251 Mon Sep 17 00:00:00 2001 From: mscdex Date: Wed, 3 Jul 2013 15:20:24 -0400 Subject: [PATCH] Connection: defer fetch 'end' event until next tick Due to streams2' use of process.nextTick, without this patch body streams' 'end' events will emit after the fetch 'end' event, causing some confusion. --- lib/Connection.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Connection.js b/lib/Connection.js index 1cc5e38..a064347 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -1088,9 +1088,12 @@ Connection.prototype._resTagged = function(info) { } if (req.bodyEmitter) { + var bodyEmitter = req.bodyEmitter; if (err) - req.bodyEmitter.emit('error', err); - req.bodyEmitter.emit('end'); + bodyEmitter.emit('error', err); + process.nextTick(function() { + bodyEmitter.emit('end'); + }); } else { req.cbargs.unshift(err); req.cb && req.cb.apply(this, req.cbargs);