lib/ConnectSequence.js
function run () {
  var midSequence = this.middlewares.reverse()
  var initialNext = this.next.bind()
  var req = this.req
  var res = this.res
  var nestedCallSequence

  // create the call sequence
  nestedCallSequence = midSequence.reduce(middlewareReducer, initialNext)
  // call it
  nestedCallSequence.call()

  /**
   * Reduce the middleware sequence to a nested middleware handler sequence
   * @function
   * @inner
   * @private
   * @param {Function} callSequence intermediate resulting call sequence
   * @param {Function} middleware the current middleware
   * @returns {Function} the new intermediate resulting call sequence
   */
  function middlewareReducer (callSequence, middleware) {
    return function nextHandler (err) {
      // if the previous middleware passed an error argument
      if (err !== undefined) {
        if (isErrorHandler(middleware)) {
          // call the current middleware if it is an error handler middleware
          middleware(err, req, res, callSequence)
        } else {
          // else skip the current middleware and call the intermediate sequence
          callSequence(err)
        }
      } else {
        // if no error argument is passed
        if (isErrorHandler(middleware)) {
          // skip the current middleware if it is an errorHandler
          callSequence()
        } else {
          // else call it
          middleware(req, res, callSequence)
        }
      }
    }
  }
}
function run () {
  var midSequence = this.middlewares.reverse()
  var initialNext = this.next.bind()
  var req = this.req
  var res = this.res
  var nestedCallSequence

  // create the call sequence
  nestedCallSequence = midSequence.reduce(middlewareReducer, initialNext)
  // call it
  nestedCallSequence.call()

  /**
   * Reduce the middleware sequence to a nested middleware handler sequence
   * @function
   * @inner
   * @private
   * @param {Function} callSequence intermediate resulting call sequence
   * @param {Function} middleware the current middleware
   * @returns {Function} the new intermediate resulting call sequence
   */
  function middlewareReducer (callSequence, middleware) {
    return function nextHandler (err) {
      // if the previous middleware passed an error argument
      if (err !== undefined) {
        if (isErrorHandler(middleware)) {
          // call the current middleware if it is an error handler middleware
          middleware(err, req, res, callSequence)
        } else {
          // else skip the current middleware and call the intermediate sequence
          callSequence(err)
        }
      } else {
        // if no error argument is passed
        if (isErrorHandler(middleware)) {
          // skip the current middleware if it is an errorHandler
          callSequence()
        } else {
          // else call it
          middleware(req, res, callSequence)
        }
      }
    }
  }
}
function run ( ) { var midSequence = this . middlewares . reverse ( ) var initialNext = this . next . bind ( ) var req = this . req var res = this . res var nestedCallSequence // create the call sequence nestedCallSequence = midSequence . reduce ( middlewareReducer , initialNext ) // call it nestedCallSequence . call ( ) /**
   * Reduce the middleware sequence to a nested middleware handler sequence
   * @function
   * @inner
   * @private
   * @param {Function} callSequence intermediate resulting call sequence
   * @param {Function} middleware the current middleware
   * @returns {Function} the new intermediate resulting call sequence
   */ function middlewareReducer ( callSequence , middleware ) { return function nextHandler ( err ) { // if the previous middleware passed an error argument if ( err !== undefined ) { if ( isErrorHandler ( middleware ) ) { // call the current middleware if it is an error handler middleware middleware ( err , req , res , callSequence ) } else { // else skip the current middleware and call the intermediate sequence callSequence ( err ) } } else { // if no error argument is passed if ( isErrorHandler ( middleware ) ) { // skip the current middleware if it is an errorHandler callSequence ( ) } else { // else call it middleware ( req , res , callSequence ) } } } } }
Run sequencially each appended middleware, using the next argument as the final callback.
@method
@memberof ConnectSequence.prototype
@returns {undefined}
Run sequencially each appended middleware using the next argument as the final callback .