* 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)
| 381 | * terminated. |
| 382 | */ |
| 383 | private retire(w: PoolWorker): void { |
| 384 | const terminate = (): void => { void this.terminateStarted(w).then(() => this.retired(w)); }; |
| 385 | const cap = setTimeout(terminate, this.retireTimeoutMs); |
| 386 | cap.unref?.(); |
| 387 | let settle!: () => void; |
| 388 | const gone = new Promise<void>((resolve) => { settle = resolve; }); |
| 389 | this.retiring.set(w, { cap, gone, settle }); |
| 390 | try { |
| 391 | w.postMessage({ type: 'close' }); |
| 392 | } catch { |
| 393 | clearTimeout(cap); |
| 394 | terminate(); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | private retired(w: PoolWorker): void { |
| 399 | const retirement = this.retiring.get(w); |
no test coverage detected