Basically what I want is something like this:
this.accounts.forEach(account=> {
this.myService.sendMessage("hello", account).subscribe(
success => {
if(success)
updateProgress...
})
}
The problem with this code is that it executes everything asynchronously without waiting for the previous request. I was looking at solutions using merge and flatMap but I'm confused. I'd like to wait on the request completion before moving to next iteration. This causes a problem if I want to add a progress bar.
Solution:
Basing on the other answers this is what I've come up with:
let requestList = this.accounts.map((account, index) => {
return this.myService.sendMessage("hello", account).map(success => {
if (success)
{
// Update progress here
}
return success;
});
});
Observable.concat(...requestList).subscribe(null, null, () => {
console.log("Complete");
});