Skip to content

Commit

Permalink
refactor: drop dependency on delay (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Oct 23, 2018
1 parent cc50973 commit bb6a7c0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"@google-cloud/promisify": "^0.3.0",
"arrify": "^1.0.1",
"checkpoint-stream": "^0.1.1",
"delay": "^4.0.0",
"events-intercept": "^2.0.0",
"extend": "^3.0.1",
"google-auth-library": "^2.0.0",
Expand Down
7 changes: 5 additions & 2 deletions src/session-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
'use strict';

const {EventEmitter} = require('events');
const delay = require('delay');
const is = require('is');
const PQueue = require('p-queue');
const stackTrace = require('stack-trace');
Expand Down Expand Up @@ -659,7 +658,11 @@ class SessionPool extends EventEmitter {
const elapsed = Date.now() - startTime;
const remaining = timeout - elapsed;

promises.push(delay.reject(remaining, {value: new TimeoutError()}));
promises.push(
new Promise((_, reject) => {
setTimeout(reject.bind(null, new TimeoutError()), remaining);
})
);
}

if (!this.isFull) {
Expand Down
3 changes: 1 addition & 2 deletions test/session-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
'use strict';

const assert = require('assert');
const delay = require('delay');
const events = require('events');
const extend = require('extend');
const PQueue = require('p-queue');
Expand Down Expand Up @@ -626,7 +625,7 @@ describe('SessionPool', () => {
sessionPool.options.acquireTimeout = 1;

sessionPool._acquires.add = function(fn) {
return delay(2).then(fn);
return new Promise(r => setTimeout(r, 2)).then(fn);
};

return sessionPool._acquire().then(shouldNotBeCalled, err => {
Expand Down

0 comments on commit bb6a7c0

Please sign in to comment.