( root: string, open: () => CodeGraph, options: Parameters<CodeGraph['watch']>[0], )
| 57 | |
| 58 | /** Engines in one process share a graph; other processes share the writer slot. */ |
| 59 | export function acquireProject( |
| 60 | root: string, |
| 61 | open: () => CodeGraph, |
| 62 | options: Parameters<CodeGraph['watch']>[0], |
| 63 | ): ProjectLease { |
| 64 | root = realpathSync(root); |
| 65 | const key = canonicalProjectRoot(root); |
| 66 | let project = projects.get(key); |
| 67 | if (!project) { |
| 68 | const cg = open(); |
| 69 | project = { key, cg, refs: 0, owner: false, caughtUp: false, retirement: null, gate: null, socket: null, options, |
| 70 | dropProgress: null, retryAt: 0, retryDelayMs: 0, timer: setInterval(() => { void ready(root, project!); }, 1000) }; |
| 71 | project.timer.unref(); |
| 72 | projects.set(key, project); |
| 73 | } |
| 74 | const entry = project; |
| 75 | entry.refs++; |
| 76 | let released = false; |
| 77 | return { |
| 78 | cg: entry.cg, |
| 79 | ready: () => ready(root, entry), |
| 80 | release: () => { |
| 81 | if (released) return Promise.resolve(); |
| 82 | released = true; |
| 83 | if (--entry.refs === 0) return retire(root, entry); |
| 84 | return Promise.resolve(); |
| 85 | }, |
| 86 | }; |
| 87 | } |
| 88 | |
| 89 | function retire(root: string, project: Project): Promise<void> { |
| 90 | if (project.retirement) return project.retirement; |
no test coverage detected