Skip to content

Commit

Permalink
Fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
Browse files Browse the repository at this point in the history
…Namespace (sidorares#3091)
  • Loading branch information
jcmartineztiempo committed Dec 4, 2024
1 parent 2e62d46 commit e458059
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/pool_cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class PoolNamespace {

/**
* pool cluster execute
* @param {*} sql
* @param {*} values
* @param {*} cb
* @param {*} sql
* @param {*} values
* @param {*} cb
*/
execute(sql, values, cb) {
if (typeof values === 'function') {
Expand Down Expand Up @@ -280,4 +280,5 @@ class PoolCluster extends EventEmitter {
}
}

module.exports = PoolCluster;
exports.PoolNamespace = PoolNamespace;
exports.PoolCluster = PoolCluster;
23 changes: 22 additions & 1 deletion promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -109,7 +130,7 @@ class PromisePoolCluster extends EventEmitter {
}

of(pattern, selector) {
return new PromisePoolCluster(
return new PromisePoolNamespace(
this.poolCluster.of(pattern, selector),
this.Promise,
);
Expand Down

0 comments on commit e458059

Please sign in to comment.