【学习任务】结合洋葱圈模型图解释next的执行过程
我要参与
【学习任务】结合洋葱圈模型图解释next的执行过程
学习任务 595
等30人参与
来源: 第28周 / 前端工程师2020

题干描述:
现有如下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')
})
去发布

登录后即可发布作业,立即

我的作业

全部作业

意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师