From 6e5ccbbb0e74a24cead7fcf0d2e91e56b65fce19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Wed, 4 Dec 2024 11:17:31 +0100 Subject: [PATCH] Fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- lib/pool_cluster.js | 3 ++- promise.js | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/pool_cluster.js b/lib/pool_cluster.js index 9edda501a2..eb2ab62d4a 100644 --- a/lib/pool_cluster.js +++ b/lib/pool_cluster.js @@ -362,4 +362,5 @@ class PoolCluster extends EventEmitter { } } -module.exports = PoolCluster; +exports.PoolNamespace = PoolNamespace; +exports.PoolCluster = PoolCluster; diff --git a/promise.js b/promise.js index 4010437fe9..61b2ed656e 100644 --- a/promise.js +++ b/promise.js @@ -55,6 +55,27 @@ function createPromisePool(opts) { return new PromisePool(corePool, thePromise); } +class PromisePoolNamespace { + + constructor(poolNamespace, thePromise) { + this.poolNamespace = poolNamespace; + this.Promise = thePromise || Promise; + } + + getConnection() { + const corePoolNamespace = this.poolNamespace; + return new this.Promise((resolve, reject) => { + corePoolNamespace.getConnection((err, coreConnection) => { + if (err) { + reject(err); + } else { + resolve(new PromisePoolConnection(coreConnection, this.Promise)); + } + }); + }); + } +} + class PromisePoolCluster extends EventEmitter { constructor(poolCluster, thePromise) { super(); @@ -109,7 +130,7 @@ class PromisePoolCluster extends EventEmitter { } of(pattern, selector) { - return new PromisePoolCluster( + return new PromisePoolNamespace( this.poolCluster.of(pattern, selector), this.Promise, );