题干描述:
现有如下koa2代码,请根据"任务要求"执行下列代码,并结合洋葱圈模型图解释next的执行过程!
任务要求:
1、执行代码,在命令窗口查看打印结果
2、去掉"222"函数的next(),再在命令窗口查看打印结果
const Koa = require('koa')
const app = new Koa()
app.use(async (ctx, next)=>{
let startTime = new Date().getTime()
await next()
let endTime = new Date().getTime()
console.log(`此次的响应时间为:${endTime - startTime}ms`)
})
app.use(async (ctx, next) => {
console.log('111, 然后doSomething')
await next()
console.log('111 end')
})
app.use(async (ctx, next) => {
console.log('222, 然后doSomething')
await next()
console.log('222 end')
})
app.use(async (ctx, next) => {
console.log('333, 然后doSomething')
await next()
console.log('333 end')
})
app.listen(3333, ()=>{
// 可修改打印内容
console.log('server is running at http://localhost:3333')
})