问题描述需要输出结果为1,2,3在输出3之前阻塞执行,等待2相关代码// 请把代码文本粘贴到下方(请勿用图片代替代码)const Koa = require("koa");const app = new Koa();
app.use(async (ctx, next) => { console.log(1); await next() console.log(3);
});
app.use(async (ctx, next) => {
setTimeout(() => { console.log(2);
}, 2000);
});
app.listen(3001);console.log('http://localhost:3001')你期待的结果是什么?实际看到的错误信息又是什么?期望能按照1,2,3的顺序输出
1 回答
婷婷同学_
TA贡献1844条经验 获得超8个赞
const Koa = require("koa");const app = new Koa(); app.use(async (ctx, next) => { console.log(1); await next() console.log(3); }); app.use(async (ctx, next) => { return new Promise((resolve, reject) => { setTimeout(() => { console.log(2); resolve(); }, 2000); }) }); app.listen(3001);console.log('http://localhost:3001')
- 1 回答
- 0 关注
- 846 浏览
添加回答
举报
0/150
提交
取消