diff --git a/lib/Pool.js b/lib/Pool.js index d014052..aceaf36 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 === 'function') { + this._scheduledEviction.unref(); + } } _descheduleEvictorRun() {