| 191 | private readonly grammarBuffers?: Record<string, Uint8Array>; |
| 192 | |
| 193 | constructor(opts: ParseWorkerPoolOptions) { |
| 194 | this.languages = opts.languages; |
| 195 | this.grammarBuffers = opts.grammarBuffers; |
| 196 | this.maxSize = Math.max(1, Math.min(opts.size, MAX_PARSE_POOL_SIZE)); |
| 197 | this.recycleInterval = opts.recycleInterval ?? DEFAULT_RECYCLE_INTERVAL; |
| 198 | this.parseTimeoutMs = opts.parseTimeoutMs ?? DEFAULT_PARSE_TIMEOUT_MS; |
| 199 | this.log = opts.log ?? (() => {}); |
| 200 | if (opts.createWorker) { |
| 201 | this.createWorker = opts.createWorker; |
| 202 | } else if (opts.workerScriptPath) { |
| 203 | const scriptPath = opts.workerScriptPath; |
| 204 | this.createWorker = () => new Worker(scriptPath); |
| 205 | } else { |
| 206 | throw new Error('ParseWorkerPool requires workerScriptPath or createWorker'); |
| 207 | } |
| 208 | this.spawnOne(); // one eager warm worker, ready for the first parse |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Spawn the whole pool up front. The default demand-driven growth avoids |