It took a couple tries to make this work right, so I thought I'd share:

function pulseWhile(func, val, msec) {
    //runs [func] every [msec] milliseconds until [val] is not returned
    var d = new Deferred();
    var pulser = function() {
        if (d.fired<0) {
            var v = func();
            if (v == val) {
                window.setTimeout(arguments.callee, msec);
            }
            else {
                d.callback(v);
            }
        }
    };
    pulser();
    return d;
}

It seems like with a little more it could take an iterator as the first
arg which may or may not be useful to someone else.  If there's
interest in putting it inside MochiKit, it's released under the MIT
license and the GPL and all those things.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---

Reply via email to