From 52014e25e2948001f7de27c6076d6b16ed4abe7e Mon Sep 17 00:00:00 2001 From: Oleg Verych Date: Sat, 12 Jul 2014 11:51:56 +0300 Subject: [PATCH] group: make 'result-as-the-first-parameter' from EventEmitters available From http://howtonode.org/control-flow-part-ii: > For cases where there are more than two events > and/or they can be called multiple times, then > you need the more *powerful* and *flexible* EventEmitters. Using `group()` for `http.get()` which is EventEmitter isn't possible with Step's only "The Node.js Callback style"... --- lib/step.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/step.js b/lib/step.js index b524a6a..f8a7127 100755 --- a/lib/step.js +++ b/lib/step.js @@ -86,7 +86,7 @@ function Step() { }; // Generates a callback generator for grouped results - next.group = function () { + next.group = function (resFirst) { var localCallback = next.parallel(); var counter = 0; var pending = 0; @@ -107,12 +107,14 @@ function Step() { pending++; return function () { pending--; - // Compress the error from any result to the first argument - if (arguments[0]) { + if (resFirst) { + result[index] = arguments[0]; + } else if (arguments[0]) { + // Compress the error from any result to the first argument error = arguments[0]; + // Send the other results as arguments + result[index] = arguments[1]; } - // Send the other results as arguments - result[index] = arguments[1]; if (!lock) { check(); } }; };