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

Function promisify

packages/pg-pool/index.js:30–49  ·  view source on GitHub ↗
(Promise, callback)

Source from the content-addressed store, hash-verified

28}
29
30function promisify(Promise, callback) {
31 if (callback) {
32 return { callback: callback, result: undefined }
33 }
34 let rej
35 let res
36 const cb = function (err, client) {
37 err ? rej(err) : res(client)
38 }
39 const result = new Promise(function (resolve, reject) {
40 res = resolve
41 rej = reject
42 }).catch((err) => {
43 // replace the stack trace that leads to `TCP.onStreamRead` with one that leads back to the
44 // application that created the query
45 Error.captureStackTrace(err)
46 throw err
47 })
48 return { callback: cb, result: result }
49}
50
51function makeIdleListener(pool, client) {
52 return function idleListener(err) {

Callers 3

connectMethod · 0.85
queryMethod · 0.85
endMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected