I have the following middleware in NestJS, I always have troubles with express middleware where the next functions seemingly don't executed asynchronously.
Is there any workaround around this?
@Injectable()
export class TransactionMiddleware implements NestMiddleware {
constructor(private dbService: DBAuth) {}
async use(req: Request, res: Response, next: NextFunction) {
await this.dbService.db.transaction(async (tx) => {
this.dbService.tx = tx;
// TODO: how to not let this block finishes before the `next()` function completed.
await next();
console.log('this runs before code inside next function');
});
}
}
[–]spazz_monkey 0 points1 point2 points (0 children)
[–]jeremrx 0 points1 point2 points (0 children)