I have a function runSyncForLoop, in which I was hoping that the 2 second timeout would stop the openEmailPagefrom being called about 30 times in succession as linkArray is looped over. I did this based on a few other stackoverflow posts that I was reading through, one of which suggested deasync and another of which suggested sync. I think that the problem I am having is that ret is being set asynchronously, so this doesn't solve the problem. Right now, there is a pause, and then suddenly openEmailPage is fired the 30 times, although I was expecting there to be a two second delay between each fire.
function runSyncForLoop(linkArray){
for (i in linkArray) {
var ret = 0 ;
setTimeout(function(){
openEmailPage(linkArray[i])
},2000);
ret="hello";
}
while(ret === 0) {
require('deasync').runLoopOnce();
}
return ret;
}
This could would simply be the following if it didn't have the deasync/timeout stuff:
function runSyncForLoop(linkArray){
for (i in linkArray) {
openEmailPage(linkArray[i])
}
}
I'm trying to figure out how to run this with a two second delay between each call of openEmailPage(linkArray[i])