MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / acquire

Function acquire

packages/plugins/mcp/src/sdk/connection-pool.ts:60–84  ·  view source on GitHub ↗
(key: string, connector: McpConnector, forceFresh: boolean)

Source from the content-addressed store, hash-verified

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

Callers 1

runFunction · 0.85

Calls 4

closeQuietlyFunction · 0.70
syncMethod · 0.65
getMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected