How to use the delay function from bluebird

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

338
339
340
341
342
343
344
345
346
347
  expect(first_mod_of_that_subreddit.name).to.equal('krispykrackers');
  expect(await first_mod_of_that_subreddit.created_utc).to.equal(1211483632);
});
it('throttles requests as specified by the config parameters', async () => {
  r.config({request_delay: 2000});
  const timer = Promise.delay(1999);
  await r.getUser('not_an_aardvark').fetch();
  await r.getUser('actually_an_aardvark').fetch();
  expect(timer.isFulfilled()).to.be.true();
});
fork icon116
star icon981
watch icon0

+ 17 other calls in file

215
216
217
218
219
220
221
222
223
    .withArgs('second').returns(Promise.resolve(expectedBrowser));

const result = pool.getBrowser('first')
    .then((browser) => {
        const secondPromise = pool.getBrowser('second');
        return Promise.delay(100)
            .then(() => pool.freeBrowser(browser))
            .then(() => secondPromise);
    });
fork icon56
star icon556
watch icon11

+ 47 other calls in file

318
319
320
321
322
323
324
325
326
    assert.calledOnce(HookRunner.prototype.runBeforeEachHooks);
});

it('should wait beforeEach hooks finish before running test', async () => {
    const afterBeforeEach = sinon.spy().named('afterBeforeEach');
    HookRunner.prototype.runBeforeEachHooks.callsFake(() => Promise.delay(10).then(afterBeforeEach));
    const test = mkTest_();

    await run_({test});
fork icon56
star icon556
watch icon11

+ 6 other calls in file

253
254
255
256
257
258
259
260
261
262
it('should load files sequentially by browsers', async () => {
    const calls = [];

    callsFakeLoadFiles_({cb: async () => {
        calls.push('loadFiles');
        await Promise.delay(1);
        calls.push('afterLoadFiles');
    }});

    const config = makeConfigStub({browsers: ['bro1', 'bro2']});
fork icon56
star icon556
watch icon11

+ 9 other calls in file

227
228
229
230
231
232
233
234
235
236
              , connection.downport );
}.bind(this));

// TBD: The Non-Preemptive Scheduler
while (1) {
  yield Promise.delay(100);
  if (this._queue.length > 512) {
    console.log('Queue reaches maximum size of 512...')

    // The last item is now lost.
fork icon23
star icon17
watch icon4

990
991
992
993
994
995
996
997
998
999
retryCount++;
var retryTime = Math.floor(Math.random() * 5000);
log.warn("parseAndCheckLogin", "Got status code " + data.statusCode + " - " + retryCount + ". attempt to retry in " + retryTime + " milliseconds...");
var url = data.request.uri.protocol + "//" + data.request.uri.hostname + data.request.uri.pathname;
if (data.request.headers["Content-Type"].split(";")[0] === "multipart/form-data") {
    return bluebird.delay(retryTime).then(() => defaultFuncs.postFormData(url, ctx.jar, data.request.formData, {}))
        .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
} else {
    return bluebird.delay(retryTime).then(() => defaultFuncs.post(url, ctx.jar, data.request.formData))
        .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
fork icon3
star icon7
watch icon2

+ 65 other calls in file

4718
4719
4720
4721
4722
4723
4724
4725
4726
4727

if (maybePromise instanceof Promise) {
    promise._propagateFrom(maybePromise, 7);
    promise._follow(maybePromise);
    return promise.then(function(value) {
        return Promise.delay(value, ms);
    });
} else {
    promise._setTrace(void 0);
    _setTimeout(afterDelay, ms, value, promise);
fork icon1
star icon2
watch icon1

87
88
89
90
91
92
93
94
95
96
// for each character in line
for(let char of line){
    if(state.isStyled){
        WriteStyledChar(char);
        if(!ignorePause && (char === '.' || char === '!' || char === '?')){
            await P.delay(speechPause);
        }
        else{
            await P.delay(state.delay);
        }
fork icon0
star icon2
watch icon1

+ 43 other calls in file

25
26
27
28
29
30
31
32
33
34
    return body;
}).catch(BPromise.TimeoutError, function () {
    throw new ConnectionError('Dead Connection, exceeded timeout limit');
}).catch(function () {
    if (retries < allowedRetries) {
        return BPromise.delay(100).then(function () {
            return retryRequest(opts, timeout, allowedRetries, retries + 1);
        });
    } else {
        throw new ConnectionError('Dead Connection, exceeded retry limit');
fork icon257
star icon0
watch icon41

23
24
25
26
27
28
29
30
31
32
var serverfns = {}; //or "require('...')"

serverfns.testOk = function () {
        console.log("testOk called");
        //Either return a Promise:
        return Promise.delay(2000)
        .then(function () {
                return "Hello";
        })
        //or a Value (resolve)
fork icon2
star icon0
watch icon7

+ 3 other calls in file

282
283
284
285
286
287
288
289
290
291
.then(function(out) {
  return out
})
.catch(function(err) {
  if (/closed/.test(err.message) && times > 1) {
    return Promise.delay(delay)
      .then(function() {
        return tryConnect(times - 1, delay * 2)
      })
  }
fork icon0
star icon1
watch icon0

285
286
287
288
289
290
291
292
293
294
    'Device worker "%s" died with code %s'
    , device.id
    , err.code
  )
  log.info('Restarting device worker "%s"', device.id)
  return Promise.delay(500)
    .then(function() {
      return work()
    })
}
fork icon0
star icon1
watch icon0

488
489
490
491
492
493
494
495
496
497
  ],
  disabled: { $ne: true }
}).toObject();

if (!user) {
  await Promise.delay(1000);
  return false;
}
try {
  await self.apos.user.verifyPassword(user, password);
fork icon539
star icon0
watch icon124

+ 26 other calls in file

34
35
36
37
38
39
40
41
42
43
const dependency = { property: originalProperty };

const callback = async (sinon) => {
  const stub = sinon.stub(dependency, 'property');
  sinon.clock.restore();
  await Bluebird.delay(10);
  assert.strictEqual(dependency.property, stub);
};

await sinonTest(callback).call(this);
fork icon0
star icon1
watch icon0

+ 2 other calls in file

59
60
61
62
63
64
65
66
67
68
69


test('Promise.prototype.spread - then formal', function (t) {
  t.plan(6)
  twice(function () {
    var trans = ins.startTransaction()
    Promise.delay(1).then(function () {
      return ['foo', 'bar']
    }).spread(function (a, b) {
      t.strictEqual(a, 'foo')
      t.strictEqual(b, 'bar')
fork icon1
star icon0
watch icon1

+ 8 other calls in file

1948
1949
1950
1951
1952
1953
1954
1955
1956
1957

socket.on('detach', function (msg) {
    // Try to detach cleanly, timeout if no response
    Promise.any([
        _this.dbg.sendDetachRequest(),
        Promise.delay(3000)
    ]).finally(function () {
        _this.dbg.disconnectDebugger();
    });
});
fork icon0
star icon1
watch icon2

+ 3 other calls in file

1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
return admin
  .save()
  .then(function(savedAdmin) {
    originalDate = savedAdmin.get('created_at');

    return Promise.delay(1000).then(function() {
      return savedAdmin.save('username', 'pablo');
    });
  })
  .then(function(updatedAdmin) {
fork icon0
star icon1
watch icon1

+ 27 other calls in file

39
40
41
42
43
44
45
46
47
48
      throw err
    }

    retries--

    return Promise.delay(1000).then(function () {
      return UpdateBucketPolicy(S3Bucket)
    })
  })
}
fork icon0
star icon0
watch icon1

+ 10 other calls in file

363
364
365
366
367
368
369
370
371
372
      // message.xp -= 2;
      // numOfLikes.innerText = parseInt(numOfLikes.innerText) - 1;
      console.log(`${username} unliked ${message.username}'s comment`);
      socket.emit("chatVote", message.username, msgBlock.id, 'unlike');
    }
  delay(250);
})

let hateBtn = msgBlock.querySelector('#hateBtn');
let hateIcon = msgBlock.querySelector('#hateIcon');
fork icon0
star icon0
watch icon2

+ 47 other calls in file

403
404
405
406
407
408
409
410
411
412
  return Promise.resolve();
}
if (/mssql/i.test(knex.client.driverName)) {
  return Promise.resolve();
}
const first = Bluebird.delay(50);
const second = first.then(() => Bluebird.delay(50));
return knex.transaction(function(trx) {
  return Promise.all([
    trx.transaction(function(trx2) {
fork icon0
star icon0
watch icon1

+ 19 other calls in file