| 204 | private readonly grammarBuffers?: Record<string, Uint8Array>; |
| 205 | |
| 206 | constructor(opts: ParseWorkerPoolOptions) { |
| 207 | this.languages = opts.languages; |
| 208 | this.grammarBuffers = opts.grammarBuffers; |
| 209 | this.maxSize = Math.max(1, Math.min(opts.size, MAX_PARSE_POOL_SIZE)); |
| 210 | this.recycleInterval = opts.recycleInterval ?? DEFAULT_RECYCLE_INTERVAL; |
| 211 | this.parseTimeoutMs = opts.parseTimeoutMs ?? DEFAULT_PARSE_TIMEOUT_MS; |
| 212 | this.log = opts.log ?? (() => {}); |
| 213 | if (opts.createWorker) { |
| 214 | this.createWorker = opts.createWorker; |
| 215 | } else if (opts.workerScriptPath) { |
| 216 | const scriptPath = opts.workerScriptPath; |
| 217 | // Deliberately no `resourceLimits.stackSizeMb`: a bigger worker stack |
| 218 | // only moves the cliff a deeply nested file falls off (#1581 — the |
| 219 | // 8 MiB main thread still dies at 100k levels). The native kernel |
| 220 | // guards its own recursion against THIS thread's real stack bounds |
| 221 | // (codegraph-kernel/src/stack.rs) and defers such a file to the wasm |
| 222 | // path, which catches its JS RangeError per file. |
| 223 | this.createWorker = () => new Worker(scriptPath); |
| 224 | } else { |
| 225 | throw new Error('ParseWorkerPool requires workerScriptPath or createWorker'); |
| 226 | } |
| 227 | this.spawnOne(); // one eager warm worker, ready for the first parse |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Spawn the whole pool up front. The default demand-driven growth avoids |