(origin, {
connections,
factory = defaultFactory,
connect,
connectTimeout,
tls,
maxCachedSessions,
socketPath,
autoSelectFamily,
autoSelectFamilyAttemptTimeout,
allowH2,
useH2c,
clientTtl,
...options
} = {})
| 27 | |
| 28 | class Pool extends PoolBase { |
| 29 | constructor (origin, { |
| 30 | connections, |
| 31 | factory = defaultFactory, |
| 32 | connect, |
| 33 | connectTimeout, |
| 34 | tls, |
| 35 | maxCachedSessions, |
| 36 | socketPath, |
| 37 | autoSelectFamily, |
| 38 | autoSelectFamilyAttemptTimeout, |
| 39 | allowH2, |
| 40 | useH2c, |
| 41 | clientTtl, |
| 42 | ...options |
| 43 | } = {}) { |
| 44 | if (connections != null && (!Number.isFinite(connections) || connections < 0)) { |
| 45 | throw new InvalidArgumentError('invalid connections') |
| 46 | } |
| 47 | |
| 48 | if (typeof factory !== 'function') { |
| 49 | throw new InvalidArgumentError('factory must be a function.') |
| 50 | } |
| 51 | |
| 52 | if (connect != null && typeof connect !== 'function' && typeof connect !== 'object') { |
| 53 | throw new InvalidArgumentError('connect must be a function or an object') |
| 54 | } |
| 55 | |
| 56 | if (typeof connect !== 'function') { |
| 57 | connect = buildConnector({ |
| 58 | ...tls, |
| 59 | maxCachedSessions, |
| 60 | allowH2, |
| 61 | useH2c, |
| 62 | socketPath, |
| 63 | timeout: connectTimeout, |
| 64 | ...(typeof autoSelectFamily === 'boolean' ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined), |
| 65 | ...connect |
| 66 | }) |
| 67 | } |
| 68 | |
| 69 | super(options) |
| 70 | |
| 71 | this[kConnections] = connections || null |
| 72 | this[kUrl] = util.parseOrigin(origin) |
| 73 | this[kOptions] = { ...util.deepClone(options), connect, allowH2, useH2c, clientTtl, socketPath } |
| 74 | this[kFactory] = factory |
| 75 | |
| 76 | this.on('connect', (origin, targets) => { |
| 77 | if (clientTtl != null && clientTtl > 0) { |
| 78 | for (const target of targets) { |
| 79 | Object.assign(target, { ttl: Date.now() }) |
| 80 | } |
| 81 | } |
| 82 | }) |
| 83 | |
| 84 | this.on('connectionError', (origin, targets, error) => { |
| 85 | // If a connection error occurs, we remove the client from the pool, |
| 86 | // and emit a connectionError event. They will not be re-used. |
nothing calls this directly
no test coverage detected