From bb6a7c06c810af41f9b3f9a94520d8da2106be95 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Mon, 22 Oct 2018 19:40:11 -0700 Subject: [PATCH] refactor: drop dependency on delay (#383) --- package.json | 1 - src/session-pool.js | 7 +++++-- test/session-pool.js | 3 +-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index dc972a873..d3e248e06 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/session-pool.js b/src/session-pool.js index 237c2254f..72e7ce50a 100644 --- a/src/session-pool.js +++ b/src/session-pool.js @@ -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'); @@ -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) { diff --git a/test/session-pool.js b/test/session-pool.js index 72e7da89c..00daa5108 100644 --- a/test/session-pool.js +++ b/test/session-pool.js @@ -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'); @@ -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 => {