title: Nodejs / Q : Chaining promises sequentially
body: <p>I want to do something really simple, but i don't understand a little thing ...</p>
  
  <pre><code>var Q = require('q');
  
  var funcs = ["first", "second", "third", "fourth"];
  
  function main(){
  
  // really don't know how to chain sequentially here ...
      var result = Q();
  
      funcs.forEach(function (f) {
          result = treat(f).then(f);
      });
  
  }
  
  function treat(t){
  
      var deferred = Q.defer();
  
      setTimeout(function(){
          deferred.resolve("treated "+ t); 
      },2000);
  
      return deferred.promise;
  }
  
  main();
  </code></pre>
  
  <p>I would like each element of my funcs array to be "treated" sequentially, the output would then be something like :</p>
  
  <pre><code>treated first
  //2 seconds later
  treated second
  //2 seconds later
  treated third
  //2 seconds later
  treated fourth
  </code></pre>
  
  <p>I cannot achieve that :( it should be simple , i don't catch something :(</p>