Wait for multiple promises to finish

Discussão em 'Angular' iniciado por Bas van Dijk, Outubro 29, 2024.

  1. Bas van Dijk

    Bas van Dijk Guest

    I am using the SQLStorage from the Ionic platform. The remove function returns a promise. In my code I need to remove multiple values. When these are all finished I need to execute some code.

    How can I wait for all of these and then execute a callback function?

    Code:

    removeAll() {
    this.storage.remove(key1);
    this.storage.remove(key2);
    this.storage.remove(key3);
    }


    Nesting all is a bad practise so I am looking for a decent solution :)

    removeAll() {
    return this.storage.remove(key1).then(() => {
    this.storage.remove(key2).then(() => {
    this.storage.remove(key3);
    });
    });
    };

    Continue reading...

Compartilhe esta Página