Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: drop dependency on delay #383

Merged
merged 3 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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