| 84 | }); |
| 85 | |
| 86 | const release = <A, E>(key: string, lease: ConnectionLease, exit: Exit.Exit<A, E>) => |
| 87 | Effect.gen(function* () { |
| 88 | if (shouldDropConnection(exit)) { |
| 89 | yield* closeQuietly(lease.connection); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | const displaced = yield* Effect.sync(() => { |
| 94 | if (idle.has(key)) return lease.connection; |
| 95 | idle.set(key, { connection: lease.connection, idleSince: Date.now() }); |
| 96 | return undefined; |
| 97 | }); |
| 98 | if (displaced) yield* closeQuietly(displaced); |
| 99 | }); |
| 100 | |
| 101 | const withConnection: McpConnectionPool["withConnection"] = (key, connector, use) => { |
| 102 | let reused = false; |