Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
initializePool(config = this.config) {
if (this.pool) {
this.logger.warn('The pool has already been initialized');
return;
}
const tarnPoolConfig = {
...this.getPoolSettings(config.pool),
};
// afterCreate is an internal knex param, tarn.js does not support it
if (tarnPoolConfig.afterCreate) {
delete tarnPoolConfig.afterCreate;
}
this.pool = new Pool(tarnPoolConfig);
},
this._poolDestroy(connection).then(() => {
if (!this._connecting) {
debug('pool(%d): not connecting, exiting silently (was close called before connection established?)', IDS.get(this))
return
}
// prepare pool
this.pool = new tarn.Pool(
Object.assign({
create: () => this._poolCreate()
.then(connection => {
this._healthy = true
return connection
})
.catch(err => {
if (this.pool.numUsed() + this.pool.numFree() <= 0) {
this._healthy = false
}
throw err
}),
validate: this._poolValidate.bind(this),
destroy: this._poolDestroy.bind(this),
max: 10,
min: 0,
_createClientPool({ host, port, connections }) {
return new Pool({
create: () => new Http2Client(host, port).connect(),
validate: client => client.ready,
destroy: client => client.destroy(),
min: 0,
max: connections
})
}