Break out of loop on demand - by button click, keyboard... ?
Hello;
I have a script that pols a folder for files despited by some other process (getDataFiles()); when it finds a file, it processes it (processData()), then moves it to a different folder and pols for a newly depostied file. This is the loop you see below.
I’m looking for a way to break the loop. I can’t, from what I’ve read, set the “isStopped” variable via a button click because of the single-thread nature of Javascript processing.
Ideally, I’d like to have a UI with a start and stop button.
I’ve spent a lot of time Googling, to no avail. What would you suggest?
Thanks.
var isStopped = false;
...
...
...
function doIt() {
while (!isStopped) {
getDataFiles(); // read the file names into var dataFiles
for(i=0; i < dataFiles.length ;i++) { // if there are files,process them.
processData(dataFiles[i].name)
}
// wait for a bit (for new data files to be deposited)
$.sleep(2000) // wait 2 seconds
} // while !isStopped
}
