Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
107
rated 0 times [  114] [ 7]  / answers: 1 / hits: 72158  / 8 Years ago, wed, june 15, 2016, 12:00:00

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);
});
});
};

More From » angular

 Answers
2

You can use



removeAll() {
Promise.all([
this.storage.remove(key1),
this.storage.remove(key2),
this.storage.remove(key3),
]).then(value => doSomething());


See also https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise/all


[#61757] Monday, June 13, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadyngraysons

Total Points: 455
Total Questions: 109
Total Answers: 98

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
jadyngraysons questions
Thu, Apr 23, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
Tue, Dec 31, 19, 00:00, 4 Years ago
;