Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added explicit function parameters to help readability #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions lib/step.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ function Step() {
pending, counter, results, lock;

// Define the main callback that's given as `this` to the steps.
function next() {
function next(err) {
counter = pending = 0;

// Check if there are no steps left
if (steps.length === 0) {
// Throw uncaught errors
if (arguments[0]) {
throw arguments[0];
if (err) {
throw err;
}
return;
}
Expand Down Expand Up @@ -70,14 +70,14 @@ function Step() {
var index = 1 + counter++;
pending++;

return function () {
return function (err, result) {
pending--;
// Compress the error from any result to the first argument
if (arguments[0]) {
results[0] = arguments[0];
if (err) {
results[0] = err;
}
// Send the other results as arguments
results[index] = arguments[1];
results[index] = result;
if (!lock && pending === 0) {
// When all parallel branches done, call the callback
next.apply(null, results);
Expand All @@ -90,13 +90,13 @@ function Step() {
var localCallback = next.parallel();
var counter = 0;
var pending = 0;
var result = [];
var results = [];
var error = undefined;

function check() {
if (pending === 0) {
// When group is done, call the callback
localCallback(error, result);
localCallback(error, results);
}
}
process.nextTick(check); // Ensures that check is called at least once
Expand All @@ -105,14 +105,14 @@ function Step() {
return function () {
var index = counter++;
pending++;
return function () {
return function (err, result) {
pending--;
// Compress the error from any result to the first argument
if (arguments[0]) {
error = arguments[0];
if (err) {
error = err;
}
// Send the other results as arguments
result[index] = arguments[1];
results[index] = result;
if (!lock) { check(); }
};
};
Expand Down