I am going to save data using for loops after each iteration, I have some task to do ex doSomeWork() but here this function iterates before query return any response,
I want to make this for loop as it should run doSomeTask function and next lop must iterate after query completion as my function depends on some unique value.
for (let i of data.rows) {
if(i.doc.sync === false || i.doc.syncFail === true)
{
PouchDb.post(i.doc).then((response) => {
console.log(response);
doSomeWork(response);
})
}
}
I think you can use async/await for what you want to achieve.
Try this:
for (let i of data.rows) {
if(i.doc.sync === false || i.doc.syncFail === true)
{
var response = await PouchDb.post(i.doc);
console.log(response);
doSomeWork(response);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With