* Initialization will create all pool clients instances by default * * If the pool is lazily initialized, the clients will connect when they * are requested by the user, otherwise they will all connect on initialization
()
| 188 | * are requested by the user, otherwise they will all connect on initialization |
| 189 | */ |
| 190 | async #initialize() { |
| 191 | const initialized = this.#lazy ? 0 : this.#size; |
| 192 | const clients = Array.from({ length: this.#size }, async (_e, index) => { |
| 193 | const client: PoolClient = new PoolClient( |
| 194 | this.#connection_params, |
| 195 | () => this.#available_connections!.push(client), |
| 196 | ); |
| 197 | |
| 198 | if (index < initialized) { |
| 199 | await client.connect(); |
| 200 | } |
| 201 | |
| 202 | return client; |
| 203 | }); |
| 204 | |
| 205 | this.#available_connections = new DeferredAccessStack( |
| 206 | await Promise.all(clients), |
| 207 | (client) => client.connect(), |
| 208 | (client) => client.connected, |
| 209 | ); |
| 210 | |
| 211 | this.#ended = false; |
| 212 | } |
| 213 | /** |
| 214 | * This will return the number of initialized clients in the pool |
| 215 | */ |
no test coverage detected