Over a million developers have joined DZone.

JobQueue in Javascript

·

My code snippet is a very easy and simple form of execute a jobs in javascript. it could use to organize a XMLHttpRequest's

view more info luis.caribecoders.com

function function1(){  // Function #1
 alert('Hello');
}

function function2(){  // Function #1
 alert('World');
}

var queue= [];                     // <- This is a Vector in this case a queue representation.
 queue.push(function1);      // <- storage a function #1 in a queue vector.
 queue.push(function2);      // <- storage a function #2 in a queue vector.
   while (cola.length > 0) {   // <- iterate a queue vector and execute the functions.
      (queue.shift())();            // <- Excecute the process. 
    }
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}