关于 next 函数使用 await 的问题
来源:17-14 Koa 的中间件

Richard学python
2023-09-14
以下代码最终的会得到 not found,在 next() 前加个 await/async ,就有返回结果了,原因是什么?next() 本身就会返回一个promise,不用 await/async 包装第二个中间件,next 就不用加await,搞不清楚这一块
const middle1 = (ctx, next) => {
console.log('middle1 step1');
next();
};
const middle2 = async (ctx, next) => {
console.log('middle2 step1');
const res = await axios.get('http://121.4.100.140:9091/info/1');
ctx.body = 'middleware2' + res.data.data.name;
};
写回答
1回答
-
coder_monkey
2023-09-14
async 和 await 异步处理方案可以了解一下
022023-09-15
相似问题