src/util/chain.js
function exec() {

      // Extract error from arguments.
      var err = arguments[0];

      // Abort chain on error.
      if (err) {
        fn = cfn = null;
        done.apply(null, arguments);
        return;
      }

      // Terminate if there are no functions left in the chain.
      if (!fnList.length) {
        fn = cfn = null;
        done.apply(null, arguments);
        return;
      }

      // Advance to the next function in the chain.
      fn = fnList.shift();
      var _fn = fn;

      // Extract arguments to pass into the next function.
      var ret = Array.prototype.slice.call(arguments, 1);

      // Call next function with previous return value and call back exec.
      ret.push(exec);
      var _cfn = fn.apply(null, ret); // fn(null, ret..., exec)

      // Detect when fn has completed synchronously and do not clobber the
      // internal state in that case. You're not expected to understand this.
      if (_fn !== fn) {
        return;
      }

      // Remember the cancel method for the currently executing function.
      // Detect chaining on non-cancellable function.
      if (typeof _cfn !== 'function') {
        throw new Error('chain: chaining on non-cancellable function');
      } else {
        cfn = _cfn;
      }

    }
function exec() {

      // Extract error from arguments.
      var err = arguments[0];

      // Abort chain on error.
      if (err) {
        fn = cfn = null;
        done.apply(null, arguments);
        return;
      }

      // Terminate if there are no functions left in the chain.
      if (!fnList.length) {
        fn = cfn = null;
        done.apply(null, arguments);
        return;
      }

      // Advance to the next function in the chain.
      fn = fnList.shift();
      var _fn = fn;

      // Extract arguments to pass into the next function.
      var ret = Array.prototype.slice.call(arguments, 1);

      // Call next function with previous return value and call back exec.
      ret.push(exec);
      var _cfn = fn.apply(null, ret); // fn(null, ret..., exec)

      // Detect when fn has completed synchronously and do not clobber the
      // internal state in that case. You're not expected to understand this.
      if (_fn !== fn) {
        return;
      }

      // Remember the cancel method for the currently executing function.
      // Detect chaining on non-cancellable function.
      if (typeof _cfn !== 'function') {
        throw new Error('chain: chaining on non-cancellable function');
      } else {
        cfn = _cfn;
      }

    }
function exec ( ) { // Extract error from arguments. var err = arguments [ 0 ] ; // Abort chain on error. if ( err ) { fn = cfn = null ; done . apply ( null , arguments ) ; return ; } // Terminate if there are no functions left in the chain. if ( ! fnList . length ) { fn = cfn = null ; done . apply ( null , arguments ) ; return ; } // Advance to the next function in the chain. fn = fnList . shift ( ) ; var _fn = fn ; // Extract arguments to pass into the next function. var ret = Array . prototype . slice . call ( arguments , 1 ) ; // Call next function with previous return value and call back exec. ret . push ( exec ) ; var _cfn = fn . apply ( null , ret ) ; // fn(null, ret..., exec) // Detect when fn has completed synchronously and do not clobber the // internal state in that case. You're not expected to understand this. if ( _fn !== fn ) { return ; } // Remember the cancel method for the currently executing function. // Detect chaining on non-cancellable function. if ( typeof _cfn !== 'function' ) { throw new Error ( 'chain: chaining on non-cancellable function' ) ; } else { cfn = _cfn ; } }
Execute the next function in the chain. Receives the error and return values from the previous function.
Execute the next function in the chain . Receives the error and return values from the previous function .