function next(self, middleware, args) {
  var i = 0;

  var done = function() {
    // Call next middleware if no error.
    if (arguments.length === 0) {
      middleware[i++].apply(self, args);


    // If there is an error/success,
    // call reply with the response msg.
    } else {
      var a = [args[1]].concat(Array.prototype.slice.apply(arguments));
      self.reply.apply(self, a);
    }
  };

  // Invoke done() once to start.
  args.unshift(done);
  done();
}
/**
 * Provides a "middleware" like API
 * if `next` is called with a msg, it stops.
 * It can be called multiple times.
 * If called with no arguments it calls the next middleware.
 *
 * @param {Object} self
 * @param {Array.<Function>} middleware
 * @param {Array.<Object>} args
 */
Provides a "middleware" like API
if `next` is called with a msg, it stops.
It can be called multiple times.
If called with no arguments it calls the next middleware.


Provides a " middleware " like API if ` next ` is called with a msg it stops . It can be called multiple times . If called with no arguments it calls the next middleware .
function next(self, middleware, args) {
  var i = 0;
  var done = function() {
    if (arguments.length === 0) {
      middleware[i++].apply(self, args);
    } else {
      var a = [args[1]].concat(Array.prototype.slice.apply(arguments));
      self.reply.apply(self, a);
    }
  };
  args.unshift(done);
  done();
}
function next ( self , middleware , args ) { var i = 0 ; var done = function ( ) { if ( arguments . length === 0 ) { middleware [ i ++ ] . apply ( self , args ) ; } else { var a = [ args [ 1 ] ] . concat ( Array . prototype . slice . apply ( arguments ) ) ; self . reply . apply ( self , a ) ; } } ; args . unshift ( done ) ; done ( ) ; }
Provides a "middleware" like API
 if `next` is called with a msg, it stops.
Provides a " middleware " like API if ` next ` is called with a msg it stops .
// Call next middleware if no error. // If there is an error/success, // call reply with the response msg. // Invoke done() once to start.