(
integrationRow: IntegrationRow,
ref: ConnectionRef,
requestedMode: "explicit" | "background" = "explicit",
)
| 3710 | } |
| 3711 | const toolProductionInFlight = new Map<string, ToolProductionInFlight>(); |
| 3712 | const produceConnectionTools = ( |
| 3713 | integrationRow: IntegrationRow, |
| 3714 | ref: ConnectionRef, |
| 3715 | requestedMode: "explicit" | "background" = "explicit", |
| 3716 | ): Effect.Effect<readonly Tool[], ToolProductionError> => |
| 3717 | Effect.suspend(() => { |
| 3718 | const key = `${ref.owner}:${String(ref.integration)}:${String(ref.name)}`; |
| 3719 | const existing = toolProductionInFlight.get(key); |
| 3720 | if (existing) { |
| 3721 | if (requestedMode === "explicit") existing.mode = "explicit"; |
| 3722 | return Deferred.await(existing.deferred); |
| 3723 | } |
| 3724 | |
| 3725 | const entry: ToolProductionInFlight = { |
| 3726 | deferred: Deferred.makeUnsafe<readonly Tool[], ToolProductionError>(), |
| 3727 | mode: requestedMode, |
| 3728 | }; |
| 3729 | toolProductionInFlight.set(key, entry); |
| 3730 | const run = produceConnectionToolsUnshared(integrationRow, ref, () => entry.mode).pipe( |
| 3731 | Effect.exit, |
| 3732 | Effect.flatMap((exit) => Deferred.done(entry.deferred, exit)), |
| 3733 | Effect.ensuring(Effect.sync(() => void toolProductionInFlight.delete(key))), |
| 3734 | ); |
| 3735 | return Effect.forkDetach(run).pipe(Effect.andThen(Deferred.await(entry.deferred))); |
| 3736 | }); |
| 3737 | |
| 3738 | // ------------------------------------------------------------------ |
| 3739 | // Connections |
no test coverage detected