Hi all,
In the main thread, I can spin the loop with the not recommended nsiThread however I don’t need this. I need to spin the loop in a ChromeWorker. I have dispatched an async method and want to wait for it to complete. I know Task.jsm is a solution but I can’t do that without reworking this chunk of code.
Is there anyway to spin the event loop?
I tried this and it obviously didn’t wok, as it was in the while loop forever:
var lang = fetchFilestoreEntry({ mainkey:'prefs', key:'default_tesseract_lang' }); // <<<<<<< this call is async
var st = Date.now();
var i = 0;
while (!gFilestoreDefault.prefs.quick_save_dir) {
i++;
}
var end = Date.now();
console.log('prefs__quick_save_dir: took this long to get quick save dir:', (end - st), 'ms', 'ticks:', i);
Thanks that’s a good idea, but I need to hold it from returning. I can pull this off with a ctypes call to SleepEx on Windows (I didn’t test other platforms yet), but I was hoping to avoid ctypes haha.
const isDone = () => false; // your condition here
const period = 100; // choose whatever seems appropriate
function poll() {
while(true) {
isDone() ? break : SleepEx(period);
}
return isDone();
}
var rez = poll();