Open shfshanyue opened 3 years ago
const middlewares = [];
middlewares.push(async function(ctx, next) {
console.log('1');
await next();
console.log('6');
});
middlewares.push(async function(ctx, next) {
console.log('2');
await next();
console.log('5');
});
middlewares.push(async function(ctx, next) {
console.log('3');
await next();
console.log('4');
});
async function run() {
const middleware = middlewares.shift();
await (middleware && middleware({}, run));
}
run(); // expect output: 1 2 3 4 5 6
@haotie1990 你这种实现,简洁多了!
这个好棒