DISQUS

Life is grand: JavaScript function queue

  • Derek Lakin · 3 years ago
    Take a look at the event system in dojo. That may be able to do what you want.
  • Paul Watson · 3 years ago
    Thanks Derek. It could be part of the solution I think.
  • Shog9 · 3 years ago
    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
  • Rowan Nairn · 3 years ago
    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.
  • Paul Watson · 3 years ago
    Thanks for the code Shog and that is excellent news about scriptaculous, thanks Rowan.
  • ZeBadger · 2 years ago
    This queue is fantastic elegant code and really easy to use....

    http://www.safalra.com/programming/javascript/q...
  • Ady · 2 years ago
    why not use an array.

    var queue = new Array()

    //Enqueue
    queue.push(obj);

    //Dequeue
    obj = queue.shift()