()
| 685 | } |
| 686 | |
| 687 | private ensureMinPoolSize() { |
| 688 | const minPoolSize = this.options.minPoolSize; |
| 689 | if (this.poolState !== PoolState.ready) { |
| 690 | return; |
| 691 | } |
| 692 | |
| 693 | this.connections.prune(connection => this.destroyConnectionIfPerished(connection)); |
| 694 | |
| 695 | if ( |
| 696 | this.totalConnectionCount < minPoolSize && |
| 697 | this.pendingConnectionCount < this.options.maxConnecting |
| 698 | ) { |
| 699 | // NOTE: ensureMinPoolSize should not try to get all the pending |
| 700 | // connection permits because that potentially delays the availability of |
| 701 | // the connection to a checkout request |
| 702 | this.createConnection((err, connection) => { |
| 703 | if (!err && connection) { |
| 704 | this.connections.push(connection); |
| 705 | queueMicrotask(() => this.processWaitQueue()); |
| 706 | } |
| 707 | if (this.poolState === PoolState.ready) { |
| 708 | clearTimeout(this.minPoolSizeTimer); |
| 709 | this.minPoolSizeTimer = setTimeout( |
| 710 | () => this.ensureMinPoolSize(), |
| 711 | this.options.minPoolSizeCheckFrequencyMS |
| 712 | ); |
| 713 | } |
| 714 | }); |
| 715 | } else { |
| 716 | clearTimeout(this.minPoolSizeTimer); |
| 717 | this.minPoolSizeTimer = setTimeout( |
| 718 | () => this.ensureMinPoolSize(), |
| 719 | this.options.minPoolSizeCheckFrequencyMS |
| 720 | ); |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | private processWaitQueue() { |
| 725 | if (this.processingWaitQueue) { |
no test coverage detected