Here is a simplified scenario:
of([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
.pipe(
map((data) => {
let arr: Observable<any>[] = [];
for (let elem of data) {
let obj = {
title: 'foo' + 'elem',
body: 'bar' + 'elem',
userId: elem,
};
arr.push(
this.http.post(
`https://jsonplaceholder.typicode.com/posts`,
obj,
{
headers: {
'Content-type': 'application/json; charset=UTF-8',
},
}
)
);
}
return arr;
}),
concatMap((data) => forkJoin([...data])),
)
.subscribe((data) => console.log(data));
My understanding is that in this case all requests are going to be fired in parallel because that's what forkJoin([...data])
does. I'm trying to figure out how I can fire a request only if the previous one completed (succeeded or failed, doesn't matter).
I'd appreciate any suggestions or help. Thanks.
just use concat instead of forkJoin
concatMap((data) => concat(data)),
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments