Skip to content

Commit 6d3449c

Browse files
committed
Make client.queryQueue private (with deprecation)
1 parent d995350 commit 6d3449c

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

packages/pg/lib/client.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Client extends EventEmitter {
5454
keepAliveInitialDelayMillis: c.keepAliveInitialDelayMillis || 0,
5555
encoding: this.connectionParameters.client_encoding || 'utf8',
5656
})
57-
this.queryQueue = []
57+
this._queryQueue = []
5858
this.binary = c.binary || defaults.binary
5959
this.processID = null
6060
this.secretKey = null
@@ -98,8 +98,8 @@ class Client extends EventEmitter {
9898
this._activeQuery = null
9999
}
100100

101-
this.queryQueue.forEach(enqueueError)
102-
this.queryQueue.length = 0
101+
this._queryQueue.forEach(enqueueError)
102+
this._queryQueue.length = 0
103103
}
104104

105105
_connect(callback) {
@@ -489,8 +489,8 @@ class Client extends EventEmitter {
489489
con.on('connect', function () {
490490
con.cancel(client.processID, client.secretKey)
491491
})
492-
} else if (client.queryQueue.indexOf(query) !== -1) {
493-
client.queryQueue.splice(client.queryQueue.indexOf(query), 1)
492+
} else if (client._queryQueue.indexOf(query) !== -1) {
493+
client._queryQueue.splice(client._queryQueue.indexOf(query), 1)
494494
}
495495
}
496496

@@ -515,7 +515,7 @@ class Client extends EventEmitter {
515515

516516
_pulseQueryQueue() {
517517
if (this.readyForQuery === true) {
518-
this._activeQuery = this.queryQueue.shift()
518+
this._activeQuery = this._queryQueue.shift()
519519
const activeQuery = this._getActiveQuery()
520520
if (activeQuery) {
521521
this.readyForQuery = false
@@ -584,9 +584,9 @@ class Client extends EventEmitter {
584584
query.callback = () => {}
585585

586586
// Remove from queue
587-
const index = this.queryQueue.indexOf(query)
587+
const index = this._queryQueue.indexOf(query)
588588
if (index > -1) {
589-
this.queryQueue.splice(index, 1)
589+
this._queryQueue.splice(index, 1)
590590
}
591591

592592
this._pulseQueryQueue()
@@ -620,7 +620,7 @@ class Client extends EventEmitter {
620620
return result
621621
}
622622

623-
this.queryQueue.push(query)
623+
this._queryQueue.push(query)
624624
this._pulseQueryQueue()
625625
return result
626626
}
@@ -661,6 +661,10 @@ class Client extends EventEmitter {
661661
})
662662
}
663663
}
664+
get queryQueue() {
665+
console.warn('Warning: Client.queryQueue is deprecated and will be removed in a future version.')
666+
return this._queryQueue
667+
}
664668
}
665669

666670
// expose a Query constructor

packages/pg/test/unit/client/stream-and-query-error-interaction-tests.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ suite.test('emits end when not in query', function () {
3131
client.connection.emit('connect')
3232
process.nextTick(function () {
3333
client.connection.emit('readyForQuery')
34-
assert.equal(client.queryQueue.length, 0)
35-
assert(client.activeQuery, 'client should have issued query')
3634
process.nextTick(function () {
3735
stream.emit('close')
3836
})

0 commit comments

Comments
 (0)