MCPcopy
hub / github.com/brianc/node-postgres / _pulseQueue

Method _pulseQueue

packages/pg-pool/index.js:127–170  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

125 }
126
127 _pulseQueue() {
128 this.log('pulse queue')
129 if (this.ended) {
130 this.log('pulse queue ended')
131 return
132 }
133 if (this.ending) {
134 this.log('pulse queue on ending')
135 if (this._idle.length) {
136 this._idle.slice().map((item) => {
137 this._remove(item.client)
138 })
139 }
140 if (!this._clients.length) {
141 this.ended = true
142 this._endCallback()
143 }
144 return
145 }
146
147 // if we don't have any waiting, do nothing
148 if (!this._pendingQueue.length) {
149 this.log('no queued requests')
150 return
151 }
152 // if we don't have any idle clients and we have no more room do nothing
153 if (!this._idle.length && this._isFull()) {
154 return
155 }
156 const pendingItem = this._pendingQueue.shift()
157 if (this._idle.length) {
158 const idleItem = this._idle.pop()
159 clearTimeout(idleItem.timeoutId)
160 const client = idleItem.client
161 client.ref && client.ref()
162 const idleListener = idleItem.idleListener
163
164 return this._acquireClient(client, pendingItem, idleListener, false)
165 }
166 if (!this._isFull()) {
167 return this.newClient(pendingItem)
168 }
169 throw new Error('unexpected condition')
170 }
171
172 _remove(client, callback) {
173 const removed = removeWhere(this._idle, (item) => item.client === client)

Callers 4

connectMethod · 0.95
newClientMethod · 0.95
_releaseMethod · 0.95
endMethod · 0.95

Calls 5

_removeMethod · 0.95
_isFullMethod · 0.95
_acquireClientMethod · 0.95
newClientMethod · 0.95
refMethod · 0.45

Tested by

no test coverage detected