(w: PoolWorker, m: WorkerMessage)
| 313 | } |
| 314 | |
| 315 | private onMessage(w: PoolWorker, m: WorkerMessage): void { |
| 316 | // Before the retired-worker check: destroy() waits on this for a worker |
| 317 | // it has already let go of. |
| 318 | if (m?.type === 'ready') this.startSettled(w); |
| 319 | if (!m || !this.workers.has(w)) return; // ignore late messages from retired workers |
| 320 | if (m.type === 'ready') { |
| 321 | if (!this.pendingWorkers.delete(w)) return; // already handled this handshake |
| 322 | if (m.ok === false) { |
| 323 | this.onWorkerGone(w); // failed opens consume the same budget as crashes |
| 324 | return; |
| 325 | } |
| 326 | this.everReady = true; |
| 327 | this.idle.push(w); |
| 328 | this.drain(); |
| 329 | this.armIdleShrink(); // the last result may have come while this one started |
| 330 | return; |
| 331 | } |
| 332 | if (m.type === 'result') { |
| 333 | const job = this.inflight.get(w); |
| 334 | this.inflight.delete(w); |
| 335 | this.idle.push(w); |
| 336 | this.servedSinceShrink = true; |
| 337 | this.lastServer = w; |
| 338 | if (job) this.noteFinished(job); |
| 339 | if (job) this.settle(job, m.result ?? busyGuidance(0)); |
| 340 | this.drain(); |
| 341 | this.armIdleShrink(); |
| 342 | return; |
| 343 | } |
| 344 | if (m.type === 'trimmed') this.replaceIfHeavy(w, m.heldBytes ?? 0); |
| 345 | } |
| 346 | |
| 347 | /** Nothing queued or running, nothing starting, and every worker free. */ |
| 348 | private get quiescent(): boolean { |
no test coverage detected