DISQUS

DISQUS Hello! Life is grand is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Jump to original thread »
Author

JavaScript function queue

Started by paulmwatson · 10 months ago

Anybody know of a JavaScript function queue? The more I get into developing Ajax apps the more I need to reliably queue function calls. e.g. script.aculo.us needs to highlight an element then do a DropOut on it and then I want some JavaScript to remove the element from the DOM. You can’%3 ... Continue reading »

7 comments

  • Take a look at the event system in dojo. That may be able to do what you want.
  • Thanks Derek. It could be part of the solution I think.
  • Eh, why not...

    function fQueue()
    {
    var pos = 0;
    var queue = arguments;
    return function()
    {
    if ( pos < queue.length )
    queue[pos++]();
    }
    }

    function DoThingOne(whenDone)
    {
    document.getElementById("Output").innerHTML += "Thing One!<br>";
    whenDone();
    }

    function DoThingTwo(whenDone)
    {
    document.getElementById("Output").innerHTML += "Thing Two!<br>";
    whenDone();
    }

    function DoThingThree(whenDone)
    {
    document.getElementById("Output").innerHTML += "Thing Three!<br>";
    whenDone();
    }

    function DoThings()
    {
    var q = fQueue(
    function(){DoThingOne(q);},
    function(){DoThingTwo(q);},
    function(){DoThingThree(q);});
    q();
    }


    ...no idea if that's close to what you're looking for, but if it is and you get rich, send me a pizza.
    A *solid gold* pizza.
    With pepperoni and mushrooms.
    *Morel* mushrooms.

    -josh
  • There are queues in the new version of script.aculo.us

    see: http://www.railsdevelopment.com/2006/01/15/effe...

    Then use the afterFinish option for executing arbitrary code when the effect is done.
  • Thanks for the code Shog and that is excellent news about scriptaculous, thanks Rowan.
  • This queue is fantastic elegant code and really easy to use....

    http://www.safalra.com/programming/javascript/q...
  • why not use an array.

    var queue = new Array()

    //Enqueue
    queue.push(obj);

    //Dequeue
    obj = queue.shift()

Add New Comment

Returning? Login