I'm trying to use an async function in a NestJS interceptor. These interceptors use RxJS Observables like this:
@Injectable()
export class MyInterceptor implements NestInterceptor {
async intercept<T>(context: ExecutionContext, next: CallHandler): Promise<Observable<T>> {
await doBegin();
return next
.handle()
.pipe(
tap(
() => console.log("Done"),
(e) => console.error(e)
)
);
}
}
This works, but what if I want the methods in tap to be async? The method signature is:
(value: T) => void
Can I just put an async method in there? Or should I take a different approach?