How does async/await block in koa?

problem description

needs the output result to be 1
blocking execution before output 3, waiting for 2

related codes

/ / Please paste the code text below (do not replace the code with pictures)

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")

what result do you expect? What is the error message actually seen?

expect to output in the order of 1, 2, 3

Sep.29,2021

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')
Menu