How to use the resolve function from bluebird

Find comprehensive JavaScript bluebird.resolve code examples handpicked from public code repositorys.

192
193
194
195
196
197
198
199
200
##### 清单 9\. 异步 Promise 链式调用

```
function redis_setget_string_async() { var promise =
redis.setAsync('key', ['string']).then(function(res) { return redis.getAsync('key');
//返回 Promise }).then(function(res) { console.log(res); //打印'string' Q.resolve(res);
//返回 Promise }); return promise; }

```
fork icon166
star icon336
watch icon10

+ 5 other calls in file

145
146
147
148
149
150
151
152
153
154
const addHandler = (filePath) => {
  logger.info(`[${new Date().toLocaleTimeString()}] Reload for file add: ${filePath}`);
  if (onePagePath) {
    syncOpenedPages();
  }
  Promise.resolve('').then(async () => {
    if (site.isFilepathAPage(filePath) || site.isDependencyOfPage(filePath)) {
      return site.rebuildSourceFiles(filePath);
    }
    return site.buildAsset(filePath);
fork icon105
star icon95
watch icon13

+ 32 other calls in file

11
12
13
14
15
16
17
18
19
20
const makePool_ = ({ limit = 1, isSpecificBrowserLimiter = true } = {}) =>
    new LimitedPool(underlyingPool, { limit, isSpecificBrowserLimiter });

beforeEach(() => {
    underlyingPool = {
        getBrowser: sinon.stub().callsFake(id => Promise.resolve(stubBrowser(id))),
        freeBrowser: sinon.stub().returns(Promise.resolve()),
        cancel: sinon.stub(),
    };
});
fork icon56
star icon555
watch icon11

+ 15 other calls in file

19
20
21
22
23
24
25
26
27
28
_callCommand(command, injectAllowed) {
    return this._browser
        .evalScript(command)
        .then(result => {
            if (!result || !result.isClientScriptNotInjected) {
                return Promise.resolve(result);
            }

            if (injectAllowed) {
                return this._inject().then(() => this._callCommand(command, false));
fork icon56
star icon555
watch icon11

+ 11 other calls in file

15
16
17
18
19
20
21
22
23
24
const callsFakeLoadFiles_ = ({ cb = () => {}, tests = ["default-test"] } = {}) => {
    TestParser.prototype.loadFiles.reset();
    TestParser.prototype.loadFiles.callsFake(async function () {
        await cb.call(this);
        this._tests = tests;
        return Promise.resolve(this);
    });
};

const readTests_ = ({ opts, config, reader } = {}) => {
fork icon56
star icon555
watch icon11

+ 21 other calls in file

13
14
15
16
17
18
19
20
21
22
    {limit, isSpecificBrowserLimiter}
);

beforeEach(() => {
    underlyingPool = {
        getBrowser: sinon.stub().callsFake((id) => Promise.resolve(stubBrowser(id))),
        freeBrowser: sinon.stub().returns(Promise.resolve()),
        cancel: sinon.stub()
    };
});
fork icon56
star icon556
watch icon11

+ 15 other calls in file

368
369
370
371
372
373
374
375
376
377
378
  //  add oculus as a game store and we need to launch the game through
  //  the store - this here needs to change.
  return findGame()
    .then(steamPath => (steamPath.toLowerCase() === gamePath.toLowerCase())
      ? Promise.resolve({ launcher: 'steam', addInfo: '629730' })
      : Promise.resolve(undefined))
    .catch(() => Promise.resolve(undefined));
}


function main(context) {
fork icon46
star icon28
watch icon7

+ 153 other calls in file

228
229
230
231
232
233
234
235
236
237
// no results which is not always an error
if (isWildCardRegexSearch !== null) {
    logger.warn(
        `Running a regex or cross cluster search for ${config.index}, there is no reliable way to verify index and max_result_window`
    );
    return Promise.resolve(true);
}

return client.indices
    .getSettings({})
fork icon13
star icon48
watch icon10

+ 101 other calls in file

130
131
132
133
134
135
136
137
138
139

  if (commandOptions.fail) {
    throw new errors.CommandExecutionError(command, commandOptions.code, commandOptions.stdout, commandOptions.stderr);
  }

  return Bluebird.resolve(commandOptions.code || 0);

} else {
  if (_this.mockOptions.throwIfMockNotDefined) {
    throw new Error('Mock for "' + command + '" not defined');
fork icon8
star icon6
watch icon2

177
178
179
180
181
182
183
184
185
186
 * Create the model's table.
 * @return {Promise=} Returns a promise which will resolve when the table is ready.
 */
tableReady() {
  let model = this._getModel();
  if (!this._initModel) return Promise.resolve();
  if (this._tableReadyPromise) return this._tableReadyPromise;

  // Create the table, or push the table name in the queue.
  let r = model._thinkagain.r;
fork icon4
star icon30
watch icon4

35
36
37
38
39
40
41
42
43
44
  'properties.survey': surveyId
}).cancellable();

var boundsPromise = Promise.promisify(Response.getBounds, Response)(surveyId).cancellable();

Promise.resolve(Survey.findOne({ id: surveyId }).lean().exec())
.then(function (survey) {
  if (!survey) {
    // Cancel the count and bounds promises.
    countPromise.cancel();
fork icon14
star icon20
watch icon4

115
116
117
118
119
120
121
122
123
124
  ports.push(i);

log('Trying to find open ports between range %s and %s', options.min,
  options.max);

var promise = bluebird.resolve(ports)
  .each(function(port) {
    return that.test(port, iface)
      .then(function(open) {
        if (options.retrieve && result.length >= options.retrieve) {
fork icon8
star icon76
watch icon1

54
55
56
57
58
59
60
61
62
  else if (_.isObject(myRequests)) {
    var keys = _.keys(myRequests);

    return Promise.settle(wrapped).then(function(settledValues) {
      var resolved = _.zipObject(keys, getSettledValues(settledValues));
      return  Promise.resolve(resolved);
    });
  }
};
fork icon5
star icon56
watch icon1

1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
Promise.prototype._isBound = function () {
    return (this._bitField & 2097152) === 2097152;
};


Promise.bind = function (thisArg, value) {
    return Promise.resolve(value).bind(thisArg);
};
};


},{}],4:[function(_dereq_,module,exports){
fork icon3
star icon16
watch icon0

+ 4 other calls in file

119
120
121
122
123
124
125
126
127
128
129
        });
    });
}


function ensureDirectory(dir, isUsed, clean) {
    return (clean ? rimraf(dir) : Promise.resolve()).then(function() {
        if (!isUsed) return dir;
        return mkdirp(dir).thenReturn(dir);
    });
}
fork icon7
star icon9
watch icon0

5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
        var ret = new Promise(INTERNAL);
        setTimeout(function() { ret._fulfill(); }, ms);
        return ret;
    }
    ms = +ms;
    return Promise.resolve(value)._then(afterValue, null, null, ms, undefined);
};


Promise.prototype.delay = function (ms) {
    return delay(this, ms);
fork icon2
star icon11
watch icon0

+ 7 other calls in file

358
359
360
361
362
363
364
365
366
367
 */
authorized(request, sessionState) {
  if (sessionState.authenticated) {
    request.username = sessionState.username;
    request.ssoToken = request.cookies[TOKEN_NAME];
    return Promise.resolve({ authenticated: true, authorized: true });
  } else {
    return Promise.resolve({ authenticated: false, authorized: false });
  }
}
fork icon32
star icon5
watch icon0

+ 3 other calls in file

452
453
454
455
456
457
458
459
460
461
apiManagement(webApp) {
  const r = express.Router();
  r.post('/plugins', jsonParser, function api(req, res) {
    const pluginDef = req.body;
    //TODO rewrite to EvenEmitter
    Promise.resolve().then(() => webApp.options.newPluginHandler(pluginDef))
      .then(() => {
        res.status(200).send('plugin added');
      }, (err) => {
        res.status(400).send('ZWED0059W - failed to add the plugin: ' + err.message);
fork icon32
star icon5
watch icon0

+ 2 other calls in file

491
492
493
494
495
496
497
498
499
500
var task = payload.task;
var code = task.code;
var context = task.context;
var id = payload.id;
var promise = payload.isolated
                    ? waitForPreviousOutput(id) : Promise.resolve();


return promise
    .then(function() {
fork icon7
star icon9
watch icon4

119
120
121
122
123
124
125
126
127
128
if (proxyStr) {
    options["proxy"] = proxyStr;
}
options = this.getOptions(options);
return new Promise(function (resolve, reject) {
    var _promise = Promise.resolve(options);
    if (_this.authProvider) {
        _promise = _this.authProvider.preCall(options);
    }
    _promise.then(function (opt) {
fork icon5
star icon6
watch icon3

+ 45 other calls in file