I work in Angular 2 and I am making a series of asynchronous calls from a service. Some calls should be made conditionally only in my call chain. My initial call chain is as follows:
PSEUDO CODE
this.post().flatMap( () => this.put() ).flatMap( () => this.get() )..etc.
Then I need to conditionally attach additional asynchronous calls to my chain based on an array of variables.
I use this approach:
PSEUDO CODE
...flatMap( () => return this.additionalCallsFunction(callArray) )
.flatMap( () => this.finalPostRequest() ).subscribe(...)
additionalCallsFunction(callArray){
if(callArray.length === 0) return Observable.empty()
else { return this.get().concatMap( (res) => this.put(res).flatMap( () => {
callArray.removefirstItem()
return this.additionalCallsFunction(callArray)
});
}
Angular Observables, , . , , , , , , , . . .empty() .never(), .
/ !