I am updating a lot of records under @ngrx/data, which calls a remote API in the background to sync the database and the local store.
dataList.forEach((entity) => {
const p = this.entitySvc
.getEntityCollectionService(storeName)
.upsert(entity)
.toPromise();
promises.push(p);
});
return Promise.all(promises);
The issue I have is that the remote API call happens outside of my code, and it happens so fast the connections overwhelm the browser with:
net::ERR_INSUFFICIENT_RESOURCES
Throttling the code above doesn't help because the remote API calls happen outside of my control.
I there a way to throttle the ngrx/data remote API calls, or another way to address this issue?
Option 1
Below approach using
Observablewithout having to convert to promise first should reduce the resource usage, give it a tryNOTE: We are returning an
Observable, so where you initially called thisPromisewill need to change from a.then()to asubscribe()Option 2
If the above doesn't solve try below. The approach chains the
Observableand only processes the next request after the previous request completes.NOTE: This may be slower and you may need to indicate to the user the progress of the operation
See this Demo