UNPKG

lupdo

Version:

Database Abstraction Layer for Node js

30 lines (29 loc) 999 B
import { Pool as TarnPool } from 'tarn'; export class PdoPool extends TarnPool { 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; } } export default PdoPool;