ionic-team / ionic-team/ionic-storage
forEach should await the iteratorCallback
- Lingua principale
- TypeScript
- Stelle
- 456
- Fork
- 97
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
We have a situation where we want to clear a bunch of items from storage, and then set items immediately after. We need to await the clear step before saving to prevent the clear from clearing the newly added items.
We are using `forEach` to iterate through storage, check each item and `remove` it if need be. Since `remove` is async we are awaiting it in the `iteratorCallback` and our `iteratorCallback` is marked as async. From the source code for storage we can see that the iteratorCallback is not awaited. This means that the `forEach` Promise could resolve before all the `remove`s have completed.
Here is a sample of what our `clear` function is doing:
```
async clear() {
await this.storage.forEach(async (v, k, i) => {
if (k.startsWith(this.barcodeStorageKey) || k.startsWith(this.principleStorageKey)) {
await this.storage.remove(k);
}
});
}
```
We are using ` "@ionic/storage": "2.1.3"`
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.