The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { ScopedThreadRef } from "@t3tools/contracts"; |
| 2 | |
| 3 | import { appAtomRegistry } from "../../state/atom-registry"; |
| 4 | import { environmentThreadShells } from "../../state/threads"; |
| 5 | |
| 6 | const TIMEOUT_MS = 2_000; |
| 7 | const POLL_INTERVAL_MS = 40; |
| 8 | |
| 9 | /** Resolves true once a thread this client just created, such as a fork, reaches its state. */ |
| 10 | export async function waitForThreadShell(ref: ScopedThreadRef): Promise<boolean> { |
| 11 | const atom = environmentThreadShells.threadShellAtom(ref); |
| 12 | const read = () => appAtomRegistry.get(atom) !== null; |
| 13 | const deadline = Date.now() + TIMEOUT_MS; |
| 14 | while (!read() && Date.now() < deadline) { |
| 15 | await new Promise<void>((resolve) => { |
| 16 | setTimeout(resolve, Math.min(POLL_INTERVAL_MS, deadline - Date.now())); |
| 17 | }); |
| 18 | } |
| 19 | return read(); |
| 20 | } |