function factory() {
            console.log("NEXT "+steps.length);
            // after one use, next becomes a no-op
            if (used) {
                return;
            }
            used = true;
            // gets the next step and removes it from the list
            var step = steps.shift();
            // are there more steps?
            if (step) {
                // casts arguments to an array
                var args = Array.prototype.slice.call(arguments);
                // gets the error argument, remove it from the arguments
                var err = args.shift();
                // short circuits if error was provided
                if (err) {
                    done(err, null);
                    return;
                }
                // adds a completion callback to the arguments
                args.push(next());
                // invokes the step passing the needed arguments
                step.apply(null, args);
            } else {
                // call done, no need to manipulate arguments
                done.apply(null, arguments);
            }
        }
// uses a factory so that 'used' is local to each step
uses a factory so that 'used' is local to each step
uses a factory so that ' used ' is local to each step
function factory() {
            console.log("NEXT "+steps.length);
            if (used) {
                return;
            }
            used = true;
            var step = steps.shift();
            if (step) {
                var args = Array.prototype.slice.call(arguments);
                var err = args.shift();
                if (err) {
                    done(err, null);
                    return;
                }
                args.push(next());
                step.apply(null, args);
            } else {
                done.apply(null, arguments);
            }
        }
function factory ( ) { console . log ( "NEXT " + steps . length ) ; if ( used ) { return ; } used = true ; var step = steps . shift ( ) ; if ( step ) { var args = Array . prototype . slice . call ( arguments ) ; var err = args . shift ( ) ; if ( err ) { done ( err , null ) ; return ; } args . push ( next ( ) ) ; step . apply ( null , args ) ; } else { done . apply ( null , arguments ) ; } }
uses a factory so that 'used' is local to each step
uses a factory so that ' used ' is local to each step
// after one use, next becomes a no-op // gets the next step and removes it from the list // are there more steps? // casts arguments to an array // gets the error argument, remove it from the arguments // short circuits if error was provided // adds a completion callback to the arguments // invokes the step passing the needed arguments // call done, no need to manipulate arguments