Closed tschachten closed 5 years ago
Seems like I was using it the wrong way - the following seems to be working for me:
@Injectable()
export class SomeSagas {
public constructor() {}
onSomeEvent(events$: EventObservable<any>): Observable<ICommand> {
return events$.ofType(SomeEvent).pipe(
map((event: SomeEvent) => {
return [
new SomeCommand(uuid()),
new SomeCommand(uuid()),
];
}),
flatMap(c => c), // this is solving my issue
);
}
}
I'd like to suggest to add an example of that case to the example repository for guys like me that have not been working with RxJS before? IMO it's pretty common that you'll need to respond to an event by issuing multiple commands at some point.
Hi @tschachten, I'm glad that you found a solution :) Feel free to create a PR to the example repository, contributions are always welcome!
Just use a mergeMap next time.
mergeMap((event: SomeEvent) => of(new SomeCommand(uuid()), new SomeCommand(uuid()))),
how to get a req/res like event stream ?
I'm submitting a...
Current behavior
Whenever I try to respond to an event within a saga by issuing multiple commands an error gets thrown and my application crashes. Debugging showed me that the error seems to be 'CommandHandler not found exception!', but I don't know where this error arises from - when returning just 1 command instead of multiple ones then everything is working fine.
Expected behavior
A saga can return multiple commands in response to an event.
Minimal reproduction of the problem with instructions
My saga simplified looks like this:
What is the motivation / use case for changing the behavior?
Having a saga that is able to issue multiple commands in response to an event.
Environment