I've got a problem structuring my async code. All database-operations are async and return Promises.
I need to find a bunch of Items in the database, change them, then save them and only after all have been saved, continue with the next step in my program flow.
How can I solve this using ES6 promises?
Here is some pseudo-code illustrating my problem:
database.find("Items").then(results => {
results.forEach(result => {
result.name = "some different name";
database.save(result) // <-- is also async as find
});
return true;
}).then(next) {
// Only start here after all database.save() have been resolved
});