| 28 | } |
| 29 | |
| 30 | function 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 | |
| 51 | function makeIdleListener(pool, client) { |
| 52 | return function idleListener(err) { |