UNPKG

lightning-pool

Version:

Fastest generic Pool written with TypeScript

26 lines (25 loc) 820 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PoolRequest = void 0; function noop() { } 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); } } exports.PoolRequest = PoolRequest;