(
integrationRow: IntegrationRow,
ref: ConnectionRef,
requestedMode: "explicit" | "background" = "explicit",
)
| 3086 | } |
| 3087 | const toolProductionInFlight = new Map<string, ToolProductionInFlight>(); |
| 3088 | const produceConnectionTools = ( |
| 3089 | integrationRow: IntegrationRow, |
| 3090 | ref: ConnectionRef, |
| 3091 | requestedMode: "explicit" | "background" = "explicit", |
| 3092 | ): Effect.Effect<readonly Tool[], ToolProductionError> => |
| 3093 | Effect.suspend(() => { |
| 3094 | const key = `${ref.owner}:${String(ref.integration)}:${String(ref.name)}`; |
| 3095 | const existing = toolProductionInFlight.get(key); |
| 3096 | if (existing) { |
| 3097 | if (requestedMode === "explicit") existing.mode = "explicit"; |
| 3098 | return Deferred.await(existing.deferred); |
| 3099 | } |
| 3100 | |
| 3101 | const entry: ToolProductionInFlight = { |
| 3102 | deferred: Deferred.makeUnsafe<readonly Tool[], ToolProductionError>(), |
| 3103 | mode: requestedMode, |
| 3104 | }; |
| 3105 | toolProductionInFlight.set(key, entry); |
| 3106 | const run = produceConnectionToolsUnshared(integrationRow, ref, () => entry.mode).pipe( |
| 3107 | Effect.exit, |
| 3108 | Effect.flatMap((exit) => Deferred.done(entry.deferred, exit)), |
| 3109 | Effect.ensuring(Effect.sync(() => void toolProductionInFlight.delete(key))), |
| 3110 | ); |
| 3111 | return Effect.forkDetach(run).pipe(Effect.andThen(Deferred.await(entry.deferred))); |
| 3112 | }); |
| 3113 | |
| 3114 | // ------------------------------------------------------------------ |
| 3115 | // Connections |
no test coverage detected