fe-notes icon indicating copy to clipboard operation
fe-notes copied to clipboard

koa 洋葱模型原理

Open Inchill opened this issue 3 years ago • 0 comments

function compose (middleware = []) {
  return function (context, next) {
    function dispatch (index) {
      let fn = middleware[index]
      if (index === middleware.length) fn = next

      if (!fn) return Promise.resolve()
      try {
        return Promise.resolve(fn(context, function () {
          return dispatch(++index)
        }))
      } catch (err) {
        return Promise.reject(err)
      }
    }

    return dispatch(0)
  }
}

Inchill avatar Aug 12 '22 02:08 Inchill