lupdo
Version:
Database Abstraction Layer for Node js
34 lines (33 loc) • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PdoPool = void 0;
const tarn_1 = require("tarn");
class PdoPool extends tarn_1.Pool {
constructor(poolOptions) {
const { killResource, killTimeoutMillis, kill, ...tarnOptions } = poolOptions;
super(tarnOptions);
this.timeout = null;
this.killer = kill;
this.killResource = killResource ?? false;
this.killTimeoutMillis = killTimeoutMillis ?? 10000;
}
async destroy() {
if (this.killResource) {
this.timeout = setTimeout(async () => {
for (const used of this.used) {
await this.killer(used.resource);
this._executeEventHandlers('kill');
this.release(used.resource);
}
}, this.killTimeoutMillis);
}
const res = await super.destroy();
if (this.timeout !== null) {
clearTimeout(this.timeout);
this.timeout = null;
}
return res;
}
}
exports.PdoPool = PdoPool;
exports.default = PdoPool;