Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

forEach should await the iteratorCallback

Aperta
#154 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
typescript
Ambito
databases

Direzione di ricerca

Parti dall’implementazione di storage forEach e traccia il modo in cui invoca iteratorCallback. Verifica che la Promise restituita attenda il completamento delle chiamate async a remove, in modo che un save successivo non possa entrare in conflitto con clear; il payload non indica alcun file o test specifico.

Scritto dal modello di indicizzazione a partire dal testo della issue.

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 removes 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"

Lingua principale
TypeScript
Stelle
456
Fork
97
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ionic-team/ionic-storage

Tutte le issue di ionic-team/ionic-storage

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.