We have integrated the NestJS CQRS package into our application, which enables us to create 'sagas' through the generation of RxJS Observables that trigger various background tasks.
An issue surfaced when deploying the application on AWS Lambda - the function completes before the background tasks are finished.
Is there a different treatment of an Observable in Lambda compared to a Promise?
@Saga()
aggregateCreated = (events$: Observable<any>): Observable<AggregateCommand> => {
return events$.pipe(
ofType(AggregateCreatedEvent),
map(async (event: AggregateCreatedEvent) => {
const result = this.queueService.sendMessage(
"http://XXXXXXX", { test: "MessageContent });
await Promise.all([result]);
return;
}),
flatMap(c => c)
);
}