(
integrationRow: IntegrationRow,
ref: ConnectionRef,
requestedMode: "explicit" | "background" = "explicit",
)
| 3510 | } |
| 3511 | const toolProductionInFlight = new Map<string, ToolProductionInFlight>(); |
| 3512 | const produceConnectionTools = ( |
| 3513 | integrationRow: IntegrationRow, |
| 3514 | ref: ConnectionRef, |
| 3515 | requestedMode: "explicit" | "background" = "explicit", |
| 3516 | ): Effect.Effect<readonly Tool[], ToolProductionError> => |
| 3517 | Effect.suspend(() => { |
| 3518 | const key = `${ref.owner}:${String(ref.integration)}:${String(ref.name)}`; |
| 3519 | const existing = toolProductionInFlight.get(key); |
| 3520 | if (existing) { |
| 3521 | if (requestedMode === "explicit") existing.mode = "explicit"; |
| 3522 | return Deferred.await(existing.deferred); |
| 3523 | } |
| 3524 | |
| 3525 | const entry: ToolProductionInFlight = { |
| 3526 | deferred: Deferred.makeUnsafe<readonly Tool[], ToolProductionError>(), |
| 3527 | mode: requestedMode, |
| 3528 | }; |
| 3529 | toolProductionInFlight.set(key, entry); |
| 3530 | const run = produceConnectionToolsUnshared(integrationRow, ref, () => entry.mode).pipe( |
| 3531 | Effect.exit, |
| 3532 | Effect.flatMap((exit) => Deferred.done(entry.deferred, exit)), |
| 3533 | Effect.ensuring(Effect.sync(() => void toolProductionInFlight.delete(key))), |
| 3534 | ); |
| 3535 | return Effect.forkDetach(run).pipe(Effect.andThen(Deferred.await(entry.deferred))); |
| 3536 | }); |
| 3537 | |
| 3538 | // ------------------------------------------------------------------ |
| 3539 | // Connections |
no test coverage detected