There are quite a few questions of similar nature, I think this is a bit different.
Consider the following code:
arr = [];
this.service1.getItem()
.subscribe(item => {
Object.entries(item).forEach(([key, value]) => {
if (some_condition_true) {
this.service2.getSomeItems2(value.prop1).pipe(first())
.subscribe(result => value.xyz = result);
this.arr.push(value);
}
});
});
// This line should execute only after the 'forEach' above completes
this.someService.someMethod(arr);
The issue is I do not know in advance how many times service2.getSomeItems2
will be called.
Also, zip
and forkJoin
take Observables
but I have subscribed already. Maybe I can tap
instead of subscribe
'ing. But the fact remains about unknown number of Observables.