(
integrationRow: IntegrationRow,
ref: ConnectionRef,
requestedMode: "explicit" | "background" = "explicit",
)
| 3773 | } |
| 3774 | const toolProductionInFlight = new Map<string, ToolProductionInFlight>(); |
| 3775 | const produceConnectionTools = ( |
| 3776 | integrationRow: IntegrationRow, |
| 3777 | ref: ConnectionRef, |
| 3778 | requestedMode: "explicit" | "background" = "explicit", |
| 3779 | ): Effect.Effect<readonly Tool[], ToolProductionError> => |
| 3780 | Effect.suspend(() => { |
| 3781 | const key = `${ref.owner}:${String(ref.integration)}:${String(ref.name)}`; |
| 3782 | const existing = toolProductionInFlight.get(key); |
| 3783 | if (existing) { |
| 3784 | if (requestedMode === "explicit") existing.mode = "explicit"; |
| 3785 | return Deferred.await(existing.deferred); |
| 3786 | } |
| 3787 | |
| 3788 | const entry: ToolProductionInFlight = { |
| 3789 | deferred: Deferred.makeUnsafe<readonly Tool[], ToolProductionError>(), |
| 3790 | mode: requestedMode, |
| 3791 | }; |
| 3792 | toolProductionInFlight.set(key, entry); |
| 3793 | const run = produceConnectionToolsUnshared(integrationRow, ref, () => entry.mode).pipe( |
| 3794 | Effect.exit, |
| 3795 | Effect.flatMap((exit) => Deferred.done(entry.deferred, exit)), |
| 3796 | Effect.ensuring(Effect.sync(() => void toolProductionInFlight.delete(key))), |
| 3797 | ); |
| 3798 | return Effect.forkDetach(run).pipe(Effect.andThen(Deferred.await(entry.deferred))); |
| 3799 | }); |
| 3800 | |
| 3801 | // ------------------------------------------------------------------ |
| 3802 | // Connections |
no test coverage detected