返回 DeepSeek-Reasonix
workspaceGitStats.ts
根目录 / desktop / frontend / src / lib / workspaceGitStats.ts
1 import { app } from "./bridge";
2 import type { WorkspaceChangesView } from "./types";
3
4 // A launcher can unmount while its RPC is still running. Hold the scope until
5 // completion so a replacement launcher cannot overlap that scan or reuse it.
6 const inflight = new Map<string, Promise<WorkspaceChangesView>>();
7
8 export async function loadWorkspaceGitStats(tabId: string, workspaceRoot: string, current: () => boolean) {
9 const key = JSON.stringify([tabId, workspaceRoot]);
10 while (inflight.has(key)) {
11 try { await inflight.get(key); } catch { /* The replacement owns its own result. */ }
12 if (!current()) return undefined;
13 }
14 if (!current()) return undefined;
15 const request = app.WorkspaceGitStatsForTab(tabId, workspaceRoot);
16 inflight.set(key, request);
17 try {
18 return await request;
19 } finally {
20 if (inflight.get(key) === request) inflight.delete(key);
21 }
22 }
23
23 lines TYPESCRIPT