freecog.net

AsyncQueue Documentation

AsyncQueue is a JavaScript class that simplifies breaking up long-running, blocking operations to avoid the dreaded "Warning: Unresponsive script" dialog box.

Author:Tom W.M.
Date:July 16, 2006
Licence:MIT
Source Code:AsyncQueue.js

Example Usage

(new AsyncQueue(this)).next(function(){
        // do stuff
}).next(function(){
        // do more stuff
        // Note that the this in this function is the same
        // as that which was passed to the AsyncQueue constructor.
}).loop(function(){
        // stuff to repeat
        if (stuff_is_done) {
                // leave the loop
                throw AsyncQueue.StopLoop;
        }
}).loopResult(this.get_function_to_repeat)
.defer(this.deferred_to_wait_for)
.defer(function func_returning_a_deferred(){
        return new MochiKit.Async.Deferred();
}).go(); // get moving!
// If MochiKit.Async is loaded, go() returns a deferred.

// If you don't like the chained method, more
// normal usage works just fine.
var a = new AsyncQueue(this);
a.next(function() {
        // do stuff
});
var deferred = a.go();