(key: string, connector: McpConnector, forceFresh: boolean)
| 65 | const idle = new Map<string, IdleConnection>(); |
| 66 | |
| 67 | const acquire = (key: string, connector: McpConnector, forceFresh: boolean) => |
| 68 | Effect.gen(function* () { |
| 69 | if (forceFresh) { |
| 70 | const connection = yield* connector; |
| 71 | return { connection, reused: false } satisfies ConnectionLease; |
| 72 | } |
| 73 | |
| 74 | const taken = yield* Effect.sync(() => { |
| 75 | const entry = idle.get(key); |
| 76 | if (!entry) return { connection: undefined, expired: undefined }; |
| 77 | idle.delete(key); |
| 78 | if (Date.now() - entry.idleSince >= IDLE_TTL_MS) { |
| 79 | return { connection: undefined, expired: entry.connection }; |
| 80 | } |
| 81 | return { connection: entry.connection, expired: undefined }; |
| 82 | }); |
| 83 | |
| 84 | if (taken.expired) yield* closeQuietly(taken.expired); |
| 85 | if (taken.connection) { |
| 86 | return { connection: taken.connection, reused: true } satisfies ConnectionLease; |
| 87 | } |
| 88 | |
| 89 | const connection = yield* connector; |
| 90 | return { connection, reused: false } satisfies ConnectionLease; |
| 91 | }); |
| 92 | |
| 93 | const release = <A, E>(key: string, lease: ConnectionLease, exit: Exit.Exit<A, E>) => |
| 94 | Effect.gen(function* () { |
no test coverage detected