Our backend didn't have an endpoint to save an array of persons. Forkjoin didn't work either as it fired off post requests too rapidly.
We tried an interval first without the awaiter:
let sub =
interval(2000).subscribe(async (k) =>
let person = this.persons[k];
if (person) {
await this.savePerson(persons);
}else{
sub.unsubscribe();
}
That didn't work because all of the posts were fired at the same time as if they were waiting for the post-angular-rendering cycle. We know from past experience that http requests don't happen until the end. After putting in the await coupled with this code we were in luck.
async savePerson(person) {
return new Promise((resolve, reject) => {
this.rs.postPerson(person).subscribe(
(result) => {
resolve(result);
},
(error) => {
reject("");
});
}
}
Now we have full control over how fast our posts are fired off.