Typically, a long run script occurs in a loop, which is a loop.
If you need to focus on a large dataset, and this can be done asynchronously - similar to another thread, then move the processing to the web worker ( http://www.w3schools.com/HTML/html5_webworkers.asp ).
If you cannot or do not want to use a web executor, you can find your main loop that calls the long script, and you can give it the maximum number of loops, and then make it return to the client using setTimeout.
Bad: (thingToProcess may be too large, resulting in a long running script)
function Process(thingToProcess){ var i; for(i=0; i < thingToProcess.length; i++){
Good: (only allows 100 iterations before returning)
function Process(thingToProcess, start){ var i; if(!start) start = 0; for(i=start; i < thingToProcess.length && i - start < 100; i++){
Both can be called in the same way:
Process(myCollectionToProcess);
N-ate source share