( root: string, open: () => CodeGraph, options: Parameters<CodeGraph['watch']>[0], )
| 37 | |
| 38 | /** Engines in one process share a graph; other processes share the writer slot. */ |
| 39 | export function acquireProject( |
| 40 | root: string, |
| 41 | open: () => CodeGraph, |
| 42 | options: Parameters<CodeGraph['watch']>[0], |
| 43 | ): ProjectLease { |
| 44 | root = realpathSync(root); |
| 45 | const key = canonicalProjectRoot(root); |
| 46 | let project = projects.get(key); |
| 47 | if (!project) { |
| 48 | const cg = open(); |
| 49 | project = { key, cg, refs: 0, owner: false, caughtUp: false, retirement: null, gate: null, socket: null, options, |
| 50 | dropProgress: null, timer: setInterval(() => { void ready(root, project!); }, 1000) }; |
| 51 | project.timer.unref(); |
| 52 | projects.set(key, project); |
| 53 | } |
| 54 | const entry = project; |
| 55 | entry.refs++; |
| 56 | let released = false; |
| 57 | return { |
| 58 | cg: entry.cg, |
| 59 | ready: () => ready(root, entry), |
| 60 | release: () => { |
| 61 | if (released) return Promise.resolve(); |
| 62 | released = true; |
| 63 | if (--entry.refs === 0) return retire(root, entry); |
| 64 | return Promise.resolve(); |
| 65 | }, |
| 66 | }; |
| 67 | } |
| 68 | |
| 69 | function retire(root: string, project: Project): Promise<void> { |
| 70 | if (project.retirement) return project.retirement; |
no test coverage detected