* Terminate a worker, but not while it is still loading grammars: wait for * the load to finish (or the worker to go away), up to `loadSettleMs` * (GRAMMAR_LOAD_SETTLE_MS — see that constant for the crash this avoids).
(w: ParsePoolWorker)
| 387 | * (GRAMMAR_LOAD_SETTLE_MS — see that constant for the crash this avoids). |
| 388 | */ |
| 389 | private async terminateSettled(w: ParsePoolWorker): Promise<void> { |
| 390 | const load = this.loads.get(w); |
| 391 | if (load) { |
| 392 | let cap: NodeJS.Timeout | undefined; |
| 393 | await Promise.race([ |
| 394 | load.settled, |
| 395 | new Promise<void>((resolve) => { cap = setTimeout(resolve, this.loadSettleMs); cap.unref?.(); }), |
| 396 | ]); |
| 397 | clearTimeout(cap); |
| 398 | } |
| 399 | try { await w.terminate(); } catch { /* already gone */ } |
| 400 | } |
| 401 | |
| 402 | private removeWorker(w: ParsePoolWorker): void { |
| 403 | this.workers.delete(w); |