The best way to control Claude Code, Codex and more from any computer or phone
| 1 | /** Hold in-place route changes while a workspace mutation is still running. */ |
| 2 | export function createDeferredNavigation() { |
| 3 | let pending = 0; |
| 4 | let latest: (() => void) | null = null; |
| 5 | return { |
| 6 | run(action: () => void) { |
| 7 | if (pending > 0) latest = action; |
| 8 | else action(); |
| 9 | }, |
| 10 | waitFor(operation: Promise<unknown>) { |
| 11 | pending += 1; |
| 12 | const release = () => { |
| 13 | pending -= 1; |
| 14 | if (pending !== 0) return; |
| 15 | const action = latest; |
| 16 | latest = null; |
| 17 | action?.(); |
| 18 | }; |
| 19 | void operation.then(release, release); |
| 20 | }, |
| 21 | }; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * The app's one thread-selection gate: a new-task branch checkout holds |
| 26 | * split-view thread selection until the draft route can be left. |
| 27 | */ |
| 28 | export const threadSelectionDeferral = createDeferredNavigation(); |