Thx,
good point.
I had a service provider that does a forEach looping through a array. Each array item itself had an array which needed looping through.
Before everything, the batch was created, then the batch was filled in the inner array. And lastly after completing of the array, the batch was committed.
Using forEach this gave the error as reported in the last link, but not caused by same reason (I think). In a for of loop, everything stayed nice and dandy.
In the Fireship link, the speaker was talking (cant remember exactly) that a for loop behaves differntly then a forEach, which can cause issues in async. I would have to look that up.
New situation: (to explain the intended logic)
async syncAll() {
const batch = this.firebase.batch();
console.warn('%c---------------- syncAll start', 'color:yellow');
for (const provider of this.stateProviderList) {
console.warn('%csyncAll for loop start', 'color:yellow', provider.getUniqueKey());
await provider.syncState(batch);
console.warn('%csyncAll for loop end', 'color:green', provider.getUniqueKey());
}
console.warn('%c---------------- syncAll end', 'color:green');
return batch.commit()
.then(res => {
console.log('syncAll syncAll batch result OK', res);
})
.catch(res => {
console.error('syncAll syncAll batch error', res);
});
}
And the syncState now has a for loop that eventually does:
batch.set(this.firebase.doc(this.firebaseStatePath + id).ref, newState.entityMap[id]);