I am working with Angular and NodeJs (with Axios) using RxJs, and currently find it very challenging to achieve this task. I will explain my problem based on a scenario.
I have an array of objects like this, with possibly even more than 100 objects:
let objArr = [{name: 'john', id: '123', country: 'usa'}, {name: 'doe', id: '456', country: 'china'}....] Then I have another 4-5 validation APIs that can be called for different params e.g. id, name and country based on each object:
api_1 = "validate_step_1/:id" api_2 = "validate_step_2/:id/:name" api_3 = "validate_step_3/:id/:country" api_4 = "validate_step_4/:id:/:name/:country" These API calls should strictly happen one after another in a sequential pattern, e.g. api_2 should only be called if api_1 returns true and so on.
What I want:
I would like to execute for-loop on the array that should run in parallel, and each object should then sequentially validate itself based on these 4 API calls. Something like sequential API calls based on each item in for-loop in parallel for all 100 objects.
Is this even possible? Also, any solutions to achieve this on the Node side are also welcomed.
What I tried
Right now I am using this method, but it's very slow, even sometimes resulting in timeout errors in Axios:
of(...this.objArr).pipe( concatMap((obj: any) => this.service.api_1(id)), concatMap((obj: any) => this.service.api_2(id, name)), concatMap((obj: any) => this.service.api_3(id, country)), concatMap((obj: any) => this.service.api_4(id, name, country)), catchError( error => this.handleError(error)) ).subscribe( success => { console.log("validation succeed", success); }, errorData => { console.log("validation failure: ", errorData); } )