MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / acquireProject

Function acquireProject

src/mcp/project-lifecycle.ts:59–87  ·  view source on GitHub ↗
(
  root: string,
  open: () => CodeGraph,
  options: Parameters<CodeGraph['watch']>[0],
)

Source from the content-addressed store, hash-verified

57
58/** Engines in one process share a graph; other processes share the writer slot. */
59export 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
89function retire(root: string, project: Project): Promise<void> {
90 if (project.retirement) return project.retirement;

Calls 7

canonicalProjectRootFunction · 0.90
readyFunction · 0.85
retireFunction · 0.70
getMethod · 0.65
resolveMethod · 0.65
openFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected