diff --git a/lib/queue-flow.js b/lib/queue-flow.js index 3d303f6..d314617 100644 --- a/lib/queue-flow.js +++ b/lib/queue-flow.js @@ -289,17 +289,21 @@ Q.prototype.waitSync = makeSync(Q.prototype.wait); // `inOut` is a helper function used by several of the Q prototype methods that // take an input queue and produce an output queue. var inOut = function inOut(outQueue, setter, callback) { - this.setHandlers(function(self, value, struct) { - if(isAsync(callback, 2)) { + if(isAsync(callback, 2)) { + this.setHandlers(function(self, value, struct) { callback(value, function(result) { self.handlerCallback(struct, setter.bind(this, value, result)); }); - } else { + }, function(end) { + outQueue[end](); + }); + } else { + this.setHandlers(function(self, value, struct) { self.handlerCallback(struct, setter.bind(this, value, callback(value))); - } - }, function(end) { - outQueue[end](); - }); + }, function(end) { + outQueue[end](); + }); + } return outQueue; };