| 267 | private readonly grammarBuffers?: Record<string, Uint8Array>; |
| 268 | |
| 269 | constructor(opts: ParseWorkerPoolOptions) { |
| 270 | this.languages = opts.languages; |
| 271 | this.grammarBuffers = opts.grammarBuffers; |
| 272 | this.maxSize = Math.max(1, Math.min(opts.size, MAX_PARSE_POOL_SIZE)); |
| 273 | this.expectedParses = opts.expectedParses; |
| 274 | this.recycleInterval = opts.recycleInterval ?? DEFAULT_RECYCLE_INTERVAL; |
| 275 | this.parseTimeoutMs = opts.parseTimeoutMs ?? DEFAULT_PARSE_TIMEOUT_MS; |
| 276 | this.loadSettleMs = opts.loadSettleMs ?? GRAMMAR_LOAD_SETTLE_MS; |
| 277 | this.log = opts.log ?? (() => {}); |
| 278 | if (opts.createWorker) { |
| 279 | this.createWorker = opts.createWorker; |
| 280 | } else if (opts.workerScriptPath) { |
| 281 | const scriptPath = opts.workerScriptPath; |
| 282 | // Deliberately no `resourceLimits.stackSizeMb`: a bigger worker stack |
| 283 | // only moves the cliff a deeply nested file falls off (#1581 — the |
| 284 | // 8 MiB main thread still dies at 100k levels). The native kernel |
| 285 | // guards its own recursion against THIS thread's real stack bounds |
| 286 | // (codegraph-kernel/src/stack.rs) and defers such a file to the wasm |
| 287 | // path, which catches its JS RangeError per file. |
| 288 | this.createWorker = () => new Worker(scriptPath); |
| 289 | } else { |
| 290 | throw new Error('ParseWorkerPool requires workerScriptPath or createWorker'); |
| 291 | } |
| 292 | this.spawnOne(); // one eager warm worker, ready for the first parse |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Spawn the pool up front, as far as the run is worth it. The default |