title: Can I make a synchronous promise in the JavaScript Q library?
body: <p>I want to do something like the following:</p>
  
  <pre><code>delay( 2500 )
    .then( function () { console.log( "Step 1 done" ) } )
    .then( delay( 7500 ) )
    .then( function () { console.log( "Step 2 done" ) } );
  </code></pre>
  
  <p>So implementation of delay has been demonstrated many times before:</p>
  
  <pre><code>function delay( ms ) {
    var deferred = Q.defer();
    setTimeout( deferred.resolve, ms );
    return deferred.promise;
  }
  </code></pre>
  
  <p>But if I run the above in node.js I get:</p>
  
  <pre><code>... delay of 2500ms
  Step 1 done
  Step 2 done
  ... delay of ~7500ms
  </code></pre>
  
  <p>rather than what I expect to see:</p>
  
  <pre><code>... delay of 2500ms
  Step 1 done
  ... delay of 7500ms
  Step 2 done
  </code></pre>
  
  <p>In the examples provided on <a href="https://github.com/kriskowal/q/wiki/Examples-Gallery">https://github.com/kriskowal/q/wiki/Examples-Gallery</a> I can't find any examples of synchronous functions (functions that return a value without any callbacks involved) chained with promise functions.</p>
  
  <p>Any ideas how to mix in synchronous actions with asynchronous promises?</p>
  
  <p>I've tried:</p>
  
  <pre><code>function synchronousPromise() {
    var deferred = Q.defer();
    console.log( "Synchronous function call" );
    deferred.resolve();
    return deferred.promise;
  }
  
  delay( 2500 )
    .then( function(){synchronousPromise()} )
    .then( function(){delay( 7500 )} )
    .then( function(){synchronousPromise()} );
  </code></pre>
  
  <p>And this outputs:</p>
  
  <pre><code>... delay of 2500ms
  Time now is 2013-06-20
  Time now is 2013-06-20
  ... delay of 7500ms
  </code></pre>
  
  <p>.. still not what I'm trying to achieve.</p>