title: Restify.js (Connect/Express) middleware ignoring call to next() within promise callback
body: <p>So. I'm experiencing some quirks when attempting to implement some basic middleware for a Restify.js application I'm building with specific regard to <code>next()</code> and promise callbacks.</p>
  
  <p>To express the problem in a generic form:</p>
  
  <pre><code>  var server = restify.createServer({
      name: config.name
    });
  </code></pre>
  
  <p>Promise resolves:</p>
  
  <pre><code>  server.use(function checkAcl(req, res, next) {
      // Promise is resolved
      var promise = function () {
        var deferred = require('q').defer();
        deferred.resolve();
        return deferred.promise;
      }
  
      promise()
        .then(function () {
          next(); // doesn't get 'called', no response sent, connection eventually times out
        }, function () {
          res.send(new restify.NotAuthorizedError());
        });
    });
    server.use(restify.bodyParser());
  
    ...
  </code></pre>
  
  <p>Promise is rejected    </p>
  
  <pre><code>  server.use(function checkAcl(req, res, next) {
      // Promise is rejected
      var promise = function () {
        var deferred = require('q').defer();
        deferred.reject();
        return deferred.promise;
      }
  
      promise()
        .then(function () {
          next(); 
        }, function () {
          res.send(new restify.NotAuthorizedError()); // this works fine
        });
      }
    });
  
    server.use(restify.bodyParser());      
  
    ...
  </code></pre>
  
  <p>Am I doing anything obviously wrong?  Any insight? It certainly seems to been related to the promise callbacks, are they somehow suppressing the call to <code>next()</code>?</p>