* Ask an idle worker to exit by itself: it closes its connections and * collects garbage first, so no marking is in flight when its thread ends * (see worker-teardown.ts). One that hasn't exited by `retireTimeoutMs` is * terminated.
(w: PoolWorker)
| 411 | * terminated. |
| 412 | */ |
| 413 | private retire(w: PoolWorker): void { |
| 414 | const terminate = (): void => { void this.terminateStarted(w).then(() => this.retired(w)); }; |
| 415 | const cap = setTimeout(terminate, this.retireTimeoutMs); |
| 416 | cap.unref?.(); |
| 417 | let settle!: () => void; |
| 418 | const gone = new Promise<void>((resolve) => { settle = resolve; }); |
| 419 | this.retiring.set(w, { cap, gone, settle }); |
| 420 | try { |
| 421 | w.postMessage({ type: 'close' }); |
| 422 | } catch { |
| 423 | clearTimeout(cap); |
| 424 | terminate(); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | private retired(w: PoolWorker): void { |
| 429 | const retirement = this.retiring.get(w); |
no test coverage detected