Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom Promise dependency to be used on clients instead of the global Promise #1570

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/client.js
Expand Up @@ -48,6 +48,7 @@ var Client = function (config) {
this.processID = null
this.secretKey = null
this.ssl = this.connectionParameters.ssl || false
this.Promise = c.Promise || global.Promise
}

util.inherits(Client, EventEmitter)
Expand All @@ -61,7 +62,7 @@ Client.prototype.connect = function (callback) {
callback(err)
return undefined
}
return Promise.reject(err)
return this.Promise.reject(err)
}
this._connecting = true

Expand Down Expand Up @@ -195,7 +196,7 @@ Client.prototype.connect = function (callback) {
})

if (!callback) {
return new global.Promise((resolve, reject) => {
return new this.Promise((resolve, reject) => {
this.once('error', reject)
this.once('connect', () => {
this.removeListener('error', reject)
Expand Down Expand Up @@ -374,7 +375,7 @@ Client.prototype.query = function (config, values, callback) {
query = new Query(config, values, callback)
if (!query.callback) {
let resolveOut, rejectOut
result = new Promise((resolve, reject) => {
result = new this.Promise((resolve, reject) => {
resolveOut = resolve
rejectOut = reject
})
Expand All @@ -400,13 +401,13 @@ Client.prototype.end = function (cb) {
// if we have an active query we need to force a disconnect
// on the socket - otherwise a hung query could block end forever
this.connection.stream.destroy(new Error('Connection terminated by user'))
return cb ? cb() : Promise.resolve()
return cb ? cb() : this.Promise.resolve()
}
if (cb) {
this.connection.end()
this.connection.once('end', cb)
} else {
return new global.Promise((resolve, reject) => {
return new this.Promise((resolve, reject) => {
this.connection.end()
this.connection.once('end', resolve)
})
Expand Down