/********************** * Implementation **********************/ function triggerHugeProcess(data, callback) { return Q.delay(0) .then(function timeoutDone() { // throw new Error('ugly') console.log('huge process running on: ', data) return 'OK' }) .nodeify(callback) }
function calculate(first, second) { return Q.delay(200) .then(function() { // throw new Error('ugly') return first*second }) }
it('Too much pending', function(done){ var lock = new AsyncLock({maxPending : 1}); lock.acquire('key', function(){ return Q().delay(20); // jshint ignore:line }); lock.acquire('key', function(){ return Q().delay(20); // jshint ignore:line }); lock.acquire('key', function(){}) .catch(function(e){ done(); }); });
it("Should fail to load a user fro, an expired JWT token", (done) => { let jwt = null; let expirationTimeout = config.session.expiresIn; config.session.expiresIn = 1; // 1 second let promise = userManager.auth("john", "123456") .then(user => { jwt = user.jwt(); config.session.expiresIn = expirationTimeout; // restore return Q.delay(1500); }) .then(() => { // jwt is now expired return userManager.fromJWT(jwt); }); expect(promise) .to.be.rejected .notify(done); })
await delay(() => {}, theReqIntervalInMs); await tenantLoader.reloadTenants();
.delay(_.random(10)) .then(function(){ tmp = value; }) .delay(_.random(20)) .then(function(){ value = tmp + 1; lock.acquire('key1', function(){ key1 = true; return Q.delay(20).then(function(){ key1 = false; }); lock.acquire('key2', function(){ key2 = true; return Q.delay(10).then(function(){ key2 = false; });
await delay(() => {}, theReqIntervalInMs); await tenantLoader.reloadTenants();