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

Method _acquireClient

packages/pg-pool/index.js:335–366  ·  view source on GitHub ↗
(client, pendingItem, idleListener, isNew)

Source from the content-addressed store, hash-verified

333
334 // acquire a client for a pending work item
335 _acquireClient(client, pendingItem, idleListener, isNew) {
336 if (isNew) {
337 this.emit('connect', client)
338 }
339
340 this.emit('acquire', client)
341
342 client.release = this._releaseOnce(client, idleListener)
343
344 client.removeListener('error', idleListener)
345
346 if (!pendingItem.timedOut) {
347 if (isNew && this.options.verify) {
348 this.options.verify(client, (err) => {
349 if (err) {
350 client.release(err)
351 return pendingItem.callback(err, undefined, NOOP)
352 }
353
354 pendingItem.callback(undefined, client, client.release)
355 })
356 } else {
357 pendingItem.callback(undefined, client, client.release)
358 }
359 } else {
360 if (isNew && this.options.verify) {
361 this.options.verify(client, client.release)
362 } else {
363 client.release()
364 }
365 }
366 }
367
368 // returns a function that wraps _release and throws if called more than once
369 _releaseOnce(client, idleListener) {

Callers 2

_pulseQueueMethod · 0.95
_afterConnectMethod · 0.95

Calls 1

_releaseOnceMethod · 0.95

Tested by

no test coverage detected