fastsync.js
function makeChainedWaterfallCallback(i, fns, cb) {
        return function() {
            var args = Array.prototype.slice.call(arguments);
            if (args[0]) {
                //ie. we had an error
                return cb(args[0]);
            }
            if (fns[i + 1]) {
                //remove error arg
                args.shift();
                args.push(makeChainedWaterfallCallback(i + 1, fns, cb));
                return fns[i + 1].apply(null, args);
            } else {
                return cb.apply(null, args);
            }
        };
    }
function makeChainedWaterfallCallback(i, fns, cb) {
        return function() {
            var args = Array.prototype.slice.call(arguments);
            if (args[0]) {
                //ie. we had an error
                return cb(args[0]);
            }
            if (fns[i + 1]) {
                //remove error arg
                args.shift();
                args.push(makeChainedWaterfallCallback(i + 1, fns, cb));
                return fns[i + 1].apply(null, args);
            } else {
                return cb.apply(null, args);
            }
        };
    }
function makeChainedWaterfallCallback ( i , fns , cb ) { return function ( ) { var args = Array . prototype . slice . call ( arguments ) ; if ( args [ 0 ] ) { //ie. we had an error return cb ( args [ 0 ] ) ; } if ( fns [ i + 1 ] ) { //remove error arg args . shift ( ) ; args . push ( makeChainedWaterfallCallback ( i + 1 , fns , cb ) ) ; return fns [ i + 1 ] . apply ( null , args ) ; } else { return cb . apply ( null , args ) ; } } ; }
Create a function that will call the next function in a chain
with the results of the original function
until the chain is finished
Create a function that will call the next function in a chain with the results of the original function until the chain is finished