()
| 137 | let index = 0; |
| 138 | |
| 139 | const next = async (): Promise<void> => { |
| 140 | if (index < this.middlewares.length) { |
| 141 | const middleware = this.middlewares[index++]; |
| 142 | const result = middleware(fullTopic, message, next); |
| 143 | if (result instanceof Promise) { |
| 144 | await result; |
| 145 | } |
| 146 | } else { |
| 147 | // 所有中间件都执行完毕,执行最终的处理函数 |
| 148 | handler(message); |
| 149 | } |
| 150 | }; |
| 151 | |
| 152 | await next(); |
| 153 | }; |