Hey,
it seems like await has no effect in a forEach Loop, I tried it with await, but the loop doesn’t pause.
I set a await for wixData.update:
ArrayFromBackend().then(async (locations) => {
locations.forEach(element => {
console.log("Start forEach");
werte.push({ lat: element.lat, lng: element.lng });
$w('#html').postMessage({ werte });
$w('#html').onMessage(async (event) => {
werte = [];
let toUpdate = {
//update fields
};
await wixData.update("Database", toUpdate);
console.log("Database Update");
});
console.log("Ende forEach");
});
});
}
//I import 2 entries from the backend ( ArrayFromBackend() )
Output:
Start ForEach
End ForEach
Start ForEach
End ForEach
Database Update
Database Update
Database Update
Database Update
When I await the postMessage, too:
await $w('#html').onMessage(async (event) => {
Output:
Start ForEach
Start ForEach
End ForEach
End ForEach
Database Update
Database Update
Database Update
Database Update