(
integrationRow: IntegrationRow,
ref: ConnectionRef,
requestedMode: "explicit" | "background" = "explicit",
)
| 3303 | } |
| 3304 | const toolProductionInFlight = new Map<string, ToolProductionInFlight>(); |
| 3305 | const produceConnectionTools = ( |
| 3306 | integrationRow: IntegrationRow, |
| 3307 | ref: ConnectionRef, |
| 3308 | requestedMode: "explicit" | "background" = "explicit", |
| 3309 | ): Effect.Effect<readonly Tool[], ToolProductionError> => |
| 3310 | Effect.suspend(() => { |
| 3311 | const key = `${ref.owner}:${String(ref.integration)}:${String(ref.name)}`; |
| 3312 | const existing = toolProductionInFlight.get(key); |
| 3313 | if (existing) { |
| 3314 | if (requestedMode === "explicit") existing.mode = "explicit"; |
| 3315 | return Deferred.await(existing.deferred); |
| 3316 | } |
| 3317 | |
| 3318 | const entry: ToolProductionInFlight = { |
| 3319 | deferred: Deferred.makeUnsafe<readonly Tool[], ToolProductionError>(), |
| 3320 | mode: requestedMode, |
| 3321 | }; |
| 3322 | toolProductionInFlight.set(key, entry); |
| 3323 | const run = produceConnectionToolsUnshared(integrationRow, ref, () => entry.mode).pipe( |
| 3324 | Effect.exit, |
| 3325 | Effect.flatMap((exit) => Deferred.done(entry.deferred, exit)), |
| 3326 | Effect.ensuring(Effect.sync(() => void toolProductionInFlight.delete(key))), |
| 3327 | ); |
| 3328 | return Effect.forkDetach(run).pipe(Effect.andThen(Deferred.await(entry.deferred))); |
| 3329 | }); |
| 3330 | |
| 3331 | // ------------------------------------------------------------------ |
| 3332 | // Connections |
no test coverage detected