How to use q

Comprehensive q code examples:

How to use q.Promise:

11
12
13
14
15
16
17
18
19
20
}

docker.client = new Docker(config.get('docker.client'));

function extractAndRepackage(project, imageId, builderId, buildId, buildLogger, dockerOptions, uuid) {
  return Q.Promise(function(resolve, reject) {
    delete dockerOptions.dockerfile;
    var extractPath = project.build.extract;
    extractPath += (extractPath[extractPath.length] === '/') ? '.'  : '/.';
    buildLogger.info('Boldly extracting produced stuff form: ', extractPath);

How to use q.resolve:

31
32
33
34
35
36
37
38
39
40
    // Use https:// rather than git:// (PR #2611)
    this._source = this._source.replace('git://', 'https://');

    // Enable shallow clones for GitHub repos
    this._shallowClone = function() {
        return Q.resolve(true);
    };
}

util.inherits(GitHubResolver, GitRemoteResolver);

How to use q.delay:

71
72
73
74
75
76
77
78
79
  self.work.initial();

  self.start = self.now();
  self.interrupted = false;

  return Q.delay(1000);

}).then(function() { /* Work: start */
  return self.work.start();

How to use q.promise:

32
33
34
35
36
37
38
39
40
41
    return this.connected;

let url = `${ window.location.origin }${ window.location.pathname }coms`;
url = url.replace('http', 'ws'); // http -> ws, https -> wss

return new Q.promise((resolve, reject) => {

    this._ws = new WebSocket(url);
    this._ws.binaryType = 'arraybuffer';
    this._opened = false;

How to use q.nfcall:

55
56
57
58
59
60
61
62
63
  type: 'token',
  token: program.password
});

const reportRateLimit = () => {
  return Q.nfcall(github.misc.rateLimit, {})
    .then(d => d.resources.core.remaining)
    .then(sideEffect(d => console.log('Rate limit remaining', d)));
};

How to use q.defer:

208
209
210
211
212
213
214
215
216
217
 * Tags "branch" off the latest imageId.
 *
 * @return promise
 */
docker.tag = function(imageId, buildId, branch) {
  var deferred  = Q.defer();
  var image     = docker.client.getImage(imageId + ':' + branch);

  image.tag({repo: imageId, tag: branch}, function() {
    deferred.resolve(docker.client.getImage(imageId));