(w: PoolWorker, m: WorkerMessage)
| 284 | } |
| 285 | |
| 286 | private onMessage(w: PoolWorker, m: WorkerMessage): void { |
| 287 | // Before the retired-worker check: destroy() waits on this for a worker |
| 288 | // it has already let go of. |
| 289 | if (m?.type === 'ready') this.startSettled(w); |
| 290 | if (!m || !this.workers.has(w)) return; // ignore late messages from retired workers |
| 291 | if (m.type === 'ready') { |
| 292 | if (!this.pendingWorkers.delete(w)) return; // already handled this handshake |
| 293 | if (m.ok === false) { |
| 294 | this.onWorkerGone(w); // failed opens consume the same budget as crashes |
| 295 | return; |
| 296 | } |
| 297 | this.everReady = true; |
| 298 | this.idle.push(w); |
| 299 | this.drain(); |
| 300 | this.armIdleShrink(); // the last result may have come while this one started |
| 301 | return; |
| 302 | } |
| 303 | if (m.type === 'result') { |
| 304 | const job = this.inflight.get(w); |
| 305 | this.inflight.delete(w); |
| 306 | this.idle.push(w); |
| 307 | this.servedSinceShrink = true; |
| 308 | this.lastServer = w; |
| 309 | if (job) this.settle(job, m.result ?? busyGuidance(0)); |
| 310 | this.drain(); |
| 311 | this.armIdleShrink(); |
| 312 | return; |
| 313 | } |
| 314 | if (m.type === 'trimmed') this.replaceIfHeavy(w, m.heldBytes ?? 0); |
| 315 | } |
| 316 | |
| 317 | /** Nothing queued or running, nothing starting, and every worker free. */ |
| 318 | private get quiescent(): boolean { |
no test coverage detected