From f127373e32c8f690802c42873c10ff5b78e7425f Mon Sep 17 00:00:00 2001 From: Yanlong Wang Date: Mon, 22 May 2023 14:20:16 +0800 Subject: [PATCH 1/3] fix: check unref before calling Make it work in browsers as well. --- lib/Pool.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Pool.js b/lib/Pool.js index d014052..8dc2b5f 100644 --- a/lib/Pool.js +++ b/lib/Pool.js @@ -152,9 +152,14 @@ class Pool extends EventEmitter { _applyDestroyTimeout(promise) { const timeoutPromise = new this._Promise((resolve, reject) => { - setTimeout(() => { + const timer = setTimeout(() => { reject(new Error("destroy timed out")); - }, this._config.destroyTimeoutMillis).unref(); + }, this._config.destroyTimeoutMillis); + + // Only relevant in Node.js and for process quitting + if (typeof timer.unref === 'function') { + timer.unref() + } }); return this._Promise.race([timeoutPromise, promise]); } @@ -402,8 +407,12 @@ class Pool extends EventEmitter { this._scheduledEviction = setTimeout(() => { this._evict(); this._scheduleEvictorRun(); - }, this._config.evictionRunIntervalMillis).unref(); - } + }, this._config.evictionRunIntervalMillis); + + // Only relevant in Node.js and for process quitting + if (typeof this.__scheduledEviction.unref === 'funciton') { + this.__scheduledEviction.unref() + } } _descheduleEvictorRun() { From 0b18db92c15a3e43582985b1ce9904cb609e0b6b Mon Sep 17 00:00:00 2001 From: Yanlong Wang Date: Mon, 22 May 2023 14:23:55 +0800 Subject: [PATCH 2/3] fix: missing semicolon --- lib/Pool.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Pool.js b/lib/Pool.js index 8dc2b5f..c332a6c 100644 --- a/lib/Pool.js +++ b/lib/Pool.js @@ -158,7 +158,7 @@ class Pool extends EventEmitter { // Only relevant in Node.js and for process quitting if (typeof timer.unref === 'function') { - timer.unref() + timer.unref(); } }); return this._Promise.race([timeoutPromise, promise]); @@ -411,7 +411,7 @@ class Pool extends EventEmitter { // Only relevant in Node.js and for process quitting if (typeof this.__scheduledEviction.unref === 'funciton') { - this.__scheduledEviction.unref() + this.__scheduledEviction.unref(); } } From 2fa71ba7680c08a7661fa109afd65b447d0679af Mon Sep 17 00:00:00 2001 From: Yanlong Wang Date: Wed, 24 May 2023 20:11:47 +0800 Subject: [PATCH 3/3] Fix typo Co-authored-by: James Butler --- lib/Pool.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Pool.js b/lib/Pool.js index c332a6c..aceaf36 100644 --- a/lib/Pool.js +++ b/lib/Pool.js @@ -410,8 +410,8 @@ class Pool extends EventEmitter { }, this._config.evictionRunIntervalMillis); // Only relevant in Node.js and for process quitting - if (typeof this.__scheduledEviction.unref === 'funciton') { - this.__scheduledEviction.unref(); + if (typeof this._scheduledEviction.unref === 'function') { + this._scheduledEviction.unref(); } }