問題描述需要輸出結果為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 關注
- 880 瀏覽
添加回答
舉報
0/150
提交
取消