UNPKG

lightning-pool

Version:

Fastest generic Pool written with TypeScript

22 lines (21 loc) 685 B
function noop() { } export class PoolRequest { constructor(pool, callback, options) { this.timedOut = false; this.created = Date.now(); this.callback = callback || noop; this.options = options; if (pool.options.acquireTimeoutMillis) { this.timeoutHandle = setTimeout(() => { this.timedOut = true; this.stopTimout(); pool.emit('request-timeout'); this.callback(new Error('Request timed out')); }, pool.options.acquireTimeoutMillis); } } stopTimout() { if (this.timeoutHandle) clearTimeout(this.timeoutHandle); } }