wait = function (time) {
    var deferred = Q.defer();
    setTimeout(function () {
      deferred.resolve();
    }, time);
    return deferred.promise;
  }
Helper that returns a promise that will resolve after waiting for a
given time (in ms).

@param {Number} time
       The time to wait.
@return {Promise} promise that resolves after time.