Hi,

You *can* use PeriodicalExecutor for this. I'm not sure it buys you
much:

function loopThroughArray(array, interval, callback) {
    var index = 0;

    setTimeout(process, interval);

    function process() {
        var rv;

        if (index < array.length) {
            try {
                rv = callback(array[index++]);
            }
            catch (e) {
            }
            if (rv !== false) {
                setTimeout(process, interval);
            }
        }
    }
}

Usage:

loopThroughArray([3, 2, 1, 0, -1, -2], 500, function(entry) {
    display(entry);
    return entry != 0;
});

Output:

3
2
1
0

Note it stops at zero, because the callback returned `false`.

You can do much the same with PeriodicalExecutor, or with setInterval.
I prefer re-scheduling the setTimeout because it's harder to lose
control of them through stoopid bugs involving forgetting to stop
them...

FWIW,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com


On Dec 17, 10:20 pm, JoJo <[email protected]> wrote:
> What's the best way to find which iteration the PeriodicalExecutuer is
> currently on? What I'm trying to do is step through an array slowly
> (period of 0.5 seconds) and having the ability to stop at an arbitrary
> time. The PeriodicalExecuter has the ability to stop, but it doesn't
> have the ability to step sequentially through an array. Or should I
> not even attempt to use PE's for this?

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" 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/prototype-scriptaculous?hl=en.

Reply via email to