index.js
function iterate(self, interceptors, args, after) {
      if (!interceptors || !interceptors.length) {
        after.apply(self, args);
        return;
      }

      var i = 0;
      var len = interceptors.length;
      if (!len) {
        after.apply(self, args);
        return;
      }

      function nextInterceptor() {
        if (i === len) {
          i++;
          after.apply(self, arguments);
        }
        else if (i < len) {
          var used = false;
          var interceptor = interceptors[i++];
          interceptor.apply(self, Array.prototype.slice.call(arguments, 1).concat(function next(err) {
            //
            // Do not allow multiple continuations
            //
            if (used) { return; }

            used = true;
            if (!err || !callback) {
              nextInterceptor.apply(null, waterfall ? arguments : args);
            } else {
              after.call(self, err);
            }
          }));
        }
      }
      nextInterceptor.apply(null, args);
    }
function iterate(self, interceptors, args, after) {
      if (!interceptors || !interceptors.length) {
        after.apply(self, args);
        return;
      }

      var i = 0;
      var len = interceptors.length;
      if (!len) {
        after.apply(self, args);
        return;
      }

      function nextInterceptor() {
        if (i === len) {
          i++;
          after.apply(self, arguments);
        }
        else if (i < len) {
          var used = false;
          var interceptor = interceptors[i++];
          interceptor.apply(self, Array.prototype.slice.call(arguments, 1).concat(function next(err) {
            //
            // Do not allow multiple continuations
            //
            if (used) { return; }

            used = true;
            if (!err || !callback) {
              nextInterceptor.apply(null, waterfall ? arguments : args);
            } else {
              after.call(self, err);
            }
          }));
        }
      }
      nextInterceptor.apply(null, args);
    }
function iterate ( self , interceptors , args , after ) { if ( ! interceptors || ! interceptors . length ) { after . apply ( self , args ) ; return ; } var i = 0 ; var len = interceptors . length ; if ( ! len ) { after . apply ( self , args ) ; return ; } function nextInterceptor ( ) { if ( i === len ) { i ++ ; after . apply ( self , arguments ) ; } else if ( i < len ) { var used = false ; var interceptor = interceptors [ i ++ ] ; interceptor . apply ( self , Array . prototype . slice . call ( arguments , 1 ) . concat ( function next ( err ) { // // Do not allow multiple continuations // if ( used ) { return ; } used = true ; if ( ! err || ! callback ) { nextInterceptor . apply ( null , waterfall ? arguments : args ) ; } else { after . call ( self , err ) ; } } ) ) ; } } nextInterceptor . apply ( null , args ) ; }
This is called in multiple temporal localities, put into a function instead of inline minor speed loss for more maintainability
This is called in multiple temporal localities put into a function instead of inline minor speed loss for more maintainability