I have an array of objects that only sometimes require a service call. The objects that require a service call take awhile to fill, so I end up with an array of the objects that didn't require a service call and then the rest at the end.
I've tried async / await, promise, and just regular subscription. Im very shaky with rxjs so I'm not sure if there's a better way to do this with observables and pipable operators
public getComments(cars: any) {
cars.forEach( async car => {
if(car.status === '1') {
// trying async / await
let repairs = await this.service.getComments(car.carId)
car.repairs = repairs
this.carRepairs.push(car)
// regular subscribe
// this.service.getComments(car.carId).subscribe(result => {
// car.repairs = result
// this.carRepairs.push(car)
// })
// trying promise
// this.service.getComments(car.carId).toPromise().then(result => {
// car.repairs = result
// })
} else {
this.carRepairs.push(car)
}
})
}
If anyone knows of a better way to do this with rxjs and keep the order, I'd love to learn.