I want to delete x rows from a YDN Database and after (!) this is done, do something else.
How can I make the "something else" wait for the delete-loop to finish?
I tried several options like
function DeleteAndThenDoSomethingElse()
{
return new Promise((resolve, reject) => {
var df = db.values('myDatabaseTable');
df.done(function (items) {
var n = items.length;
var sequence = Promise.resolve();
for (var i = 0; i < n; i++)
{
const my_i = i;
const my_premid = items[i].premid;
console.log(i + ': delete Data-ID: '+ my_premid);
sequence = sequence.then(async function() {
await db.remove('datenbank_id', my_premid).done(function() {
console.log('Delete of ' + my_premid + ' success.');
}).fail(function(e) {
console.log(e.message);
});
});
}
sequence = sequence.then(console.log('Now do something else'));
return sequence;
}
});
}
But the "Now do something else" never waits for the amount of "delete of XY success." I also tried without the async/await-addition. It seems that the db.remove always stays sync.
What do I have to change so that the deletions in the loop are executed first and then something that I chain to the promise after the loop?