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

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

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

我的作业

全部作业

微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

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