javascript - Conditional Observable chaining in angular 2 -


i working in angular 2, , making series of async calls service. of calls need made conditionally in call chain. initial call chain looks following:

pseudo code

this.post().flatmap( () => this.put() ).flatmap( () => this.get() )..etc. 

then need conditionally attach additional async calls chain based on variable array.

i'm using kind of 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)   });  } 

i'm new angular , observables, i'm not sure i'm approaching correctly. whether or not additional calls array empty or not i'm seeing initial calls happen, neither additional calls, nor final post request ever goes through when function returns. i'm not seeing errors in console. i've tried replacing .empty() .never(), no change.

any help/advice appreciated!

i had same situation, , finished using observable.of(undefined) instead of observable.empty(). don't know why, observable.empty() interrupts chain.

any further explanation appreciated.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -