| 149 | private readonly log: (msg: string) => void; |
| 150 | |
| 151 | constructor(opts: ParseWorkerPoolOptions) { |
| 152 | this.languages = opts.languages; |
| 153 | this.maxSize = Math.max(1, Math.min(opts.size, MAX_PARSE_POOL_SIZE)); |
| 154 | this.recycleInterval = opts.recycleInterval ?? DEFAULT_RECYCLE_INTERVAL; |
| 155 | this.parseTimeoutMs = opts.parseTimeoutMs ?? DEFAULT_PARSE_TIMEOUT_MS; |
| 156 | this.log = opts.log ?? (() => {}); |
| 157 | if (opts.createWorker) { |
| 158 | this.createWorker = opts.createWorker; |
| 159 | } else if (opts.workerScriptPath) { |
| 160 | const scriptPath = opts.workerScriptPath; |
| 161 | this.createWorker = () => new Worker(scriptPath); |
| 162 | } else { |
| 163 | throw new Error('ParseWorkerPool requires workerScriptPath or createWorker'); |
| 164 | } |
| 165 | this.spawnOne(); // one eager warm worker, ready for the first parse |
| 166 | } |
| 167 | |
| 168 | /** Pool size cap (for logging). */ |
| 169 | get size(): number { return this.maxSize; } |