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

Class SlowLoadWorker

__tests__/parse-pool.test.ts:320–340  ·  view source on GitHub ↗

* A fake whose grammar load takes `loadMs` (or never finishes, with `null`), and * which records when it finished loading and when it was terminated.

Source from the content-addressed store, hash-verified

318 * which records when it finished loading and when it was terminated.
319 */
320class SlowLoadWorker implements ParsePoolWorker {
321 private msgCb?: (m: unknown) => void;
322 private exitCb?: (code: number) => void;
323 loadedAt: number | null = null;
324 terminatedAt: number | null = null;
325 constructor(private loadMs: number | null) {}
326 on(event: string, cb: (...args: any[]) => void): void {
327 if (event === 'message') this.msgCb = cb;
328 else if (event === 'exit') this.exitCb = cb;
329 }
330 postMessage(msg: unknown): void {
331 if ((msg as { type: string }).type !== 'load-grammars' || this.loadMs === null) return;
332 setTimeout(() => {
333 if (this.terminatedAt !== null) return;
334 this.loadedAt = performance.now();
335 this.msgCb?.({ type: 'grammars-loaded' });
336 }, this.loadMs);
337 }
338 exit(code: number): void { this.exitCb?.(code); }
339 terminate(): Promise<number> { this.terminatedAt = performance.now(); return Promise.resolve(0); }
340}
341
342describe('teardown never terminates a worker mid-load', () => {
343 // Terminating a worker whose grammar WASM is still compiling can crash the

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected