I have two observables which I want to combine and in subscribe use either both arguments or only one. I tried .ForkJoin, .merge, .concat but could not achieve the behaviour I'm looking for.
Example:
obs1: Observable<int>;
obs2: Observable<Boolean>;
save(): Observable<any> {
return obs1.concat(obs2);
}
Then when using this function:
service.save().subscribe((first, second) => {
console.log(first); // int e.g. 1000
console.log(second); // Boolean, e.g. true
});
or
service.save().subscribe((first) => {
console.log(first); // int e.g. 1000
});
Is there a possibility to get exactly that behaviour?
Hope someone can help!
EDIT:
In my specific use case obs1<int>
and obs2<bool>
are two different post requests: obs1<int>
is the actual save function and obs2<bool>
checks if an other service is running.
The value of obs1<int>
is needed to reload the page once the request is completed and the value of obs2<bool>
is needed to display a message if the service is running - independant of obs1<int>
.
So if obs2<bool>
emits before obs1<int>
, that's not a problem, the message gets display before reload. But if obs1<int>
emits before obs2<bool>
, the page gets reloaded and the message may not be displayed anymore.
I'm telling this because with the given answers there are different behaviours whether the values get emitted before or after onComplete of the other observable and this can impact the use case.