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, );