| 420 | } |
| 421 | |
| 422 | [kOnMessage](message) { |
| 423 | switch (message.type) { |
| 424 | case messageTypes.UP_AND_RUNNING: |
| 425 | this[kIsOnline] = true; |
| 426 | return this.emit('online'); |
| 427 | case messageTypes.COULD_NOT_SERIALIZE_ERROR: |
| 428 | return this[kOnCouldNotSerializeErr](); |
| 429 | case messageTypes.ERROR_MESSAGE: |
| 430 | return this[kOnErrorMessage](message.error); |
| 431 | case messageTypes.STDIO_PAYLOAD: |
| 432 | { |
| 433 | const { stream, chunks } = message; |
| 434 | const readable = this[kParentSideStdio][stream]; |
| 435 | // This is a hot path, use a for(;;) loop |
| 436 | for (let i = 0; i < chunks.length; i++) { |
| 437 | const { chunk, encoding } = chunks[i]; |
| 438 | readable.push(chunk, encoding); |
| 439 | } |
| 440 | return; |
| 441 | } |
| 442 | case messageTypes.STDIO_WANTS_MORE_DATA: |
| 443 | { |
| 444 | const { stream } = message; |
| 445 | return this[kParentSideStdio][stream][kStdioWantsMoreDataCallback](); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | assert.fail(`Unknown worker message type ${message.type}`); |
| 450 | } |
| 451 | |
| 452 | [kDispose]() { |
| 453 | this[kHandle].onexit = null; |