Our service times out if we post too many items at the same time, what I am looking for is the RxJs operator that will allow me to serialise the post into multiple posts, something like
merge(
chunk(items, 50).map(
chunkItems => this.http.post('endPoint', chunkItems)
)
).pipe(
scan((errors, current) => [...errors, ...current], []);
)
But I don't want them to run in parallel like merge will, I want it to be like a switchMap that serialises the calls.
chunk is a function that breaks an array up into smaller chunks
export const chunk = (arr, len) => {
let chunks = [],
i = 0,
n = arr && arr.length;
while (i < n) {
chunks.push(arr.slice(i, (i += len)));
}
return chunks;
};