title: jQuery: execute array of functions sequentially (both deferreds and non-deferreds)
body: <p>I am fairly new to using Promises and have a hard time of wrapping my head around jQuery deferreds.</p>
  
  <p>What I currently have is an array of functions which I execute at a certain point:</p>
  
  <pre><code>while (queue.length) {
      (queue.shift())();   
  }
  </code></pre>
  
  <p>The problem with this is, that some of those functions are asynchronous, but I need them to run one after another.</p>
  
  <p>So some of the functions in the queue return a deferred (e.g. via jQuery.ajax()) and some are just normal functions. I would like to know if how it would be possible to execute them in order + sequentially (executing the next function only when the previous one has finished).</p>
  
  <p>I thought maybe jQuery.when would be what I am looking for, but I can't figure out how to it exactly, I came only up with this:</p>
  
  <pre><code>var deferred = jQuery.Deferred();
      while (queue.length &gt; 0) {
         deferred.done().then(queue.shift());
      }
  </code></pre>