* Check a connection into the pool. * * @param connection - The connection to check in
(connection: Connection)
| 382 | * @param connection - The connection to check in |
| 383 | */ |
| 384 | checkIn(connection: Connection): void { |
| 385 | if (!this.checkedOut.has(connection)) { |
| 386 | return; |
| 387 | } |
| 388 | const poolClosed = this.closed; |
| 389 | const stale = this.connectionIsStale(connection); |
| 390 | const willDestroy = !!(poolClosed || stale || connection.closed); |
| 391 | |
| 392 | if (!willDestroy) { |
| 393 | connection.markAvailable(); |
| 394 | this.connections.unshift(connection); |
| 395 | } |
| 396 | |
| 397 | this.checkedOut.delete(connection); |
| 398 | this.emitAndLog( |
| 399 | ConnectionPool.CONNECTION_CHECKED_IN, |
| 400 | new ConnectionCheckedInEvent(this, connection) |
| 401 | ); |
| 402 | |
| 403 | if (willDestroy) { |
| 404 | const reason = connection.closed ? 'error' : poolClosed ? 'poolClosed' : 'stale'; |
| 405 | this.destroyConnection(connection, reason); |
| 406 | } |
| 407 | |
| 408 | queueMicrotask(() => this.processWaitQueue()); |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * Clear the pool |
no test coverage detected