1-4 Koa 特点—async/await


为什么有async/await

为了使代码简洁,避免回调地狱写法出现

创建一个async/await demo

router.get('/async',async(ctx)=>{
    let result=await new Promise((resolve)=>{
        setTimeout(function() {
            resolve('2s')
        },2000)
    })
    ctx.body=result
})
koa