async function fn1(ctx, next) {
ctx.stack.push('fn1-start');
await next();
ctx.stack.push('fn1-end');
}
async function fn2(ctx, next) {
ctx.stack.push('fn2-start');
await new Promise((resolve) => setTimeout(resolve, 1000));
await next();
ctx.stack.push('fn2-end');
}
function fn3(ctx, next) {
ctx.stack.push('fn3-start');
next();
ctx.stack.push('fn3-end');
}
const composedFn = middlewares(fn1, fn2, fn3);
const context = { stack: [] };
await composedFn(context);
console.log(context.stack);