Skip to content

Commit

Permalink
worker: use _writev in internal communication
Browse files Browse the repository at this point in the history
PR-URL: #33454
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
addaleax authored and codebytere committed Jun 18, 2020
1 parent b0bce9b commit 64cae13
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions lib/internal/main/worker_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ port.on('message', (message) => {
CJSLoader.Module.runMain(filename);
}
} else if (message.type === STDIO_PAYLOAD) {
const { stream, chunk, encoding } = message;
process[stream].push(chunk, encoding);
const { stream, chunks } = message;
for (const { chunk, encoding } of chunks)
process[stream].push(chunk, encoding);
} else {
assert(
message.type === STDIO_WANTS_MORE_DATA,
Expand Down
7 changes: 5 additions & 2 deletions lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,11 @@ class Worker extends EventEmitter {
return this[kOnErrorMessage](message.error);
case messageTypes.STDIO_PAYLOAD:
{
const { stream, chunk, encoding } = message;
return this[kParentSideStdio][stream].push(chunk, encoding);
const { stream, chunks } = message;
const readable = this[kParentSideStdio][stream];
for (const { chunk, encoding } of chunks)
readable.push(chunk, encoding);
return;
}
case messageTypes.STDIO_WANTS_MORE_DATA:
{
Expand Down
7 changes: 3 additions & 4 deletions lib/internal/worker/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,11 @@ class WritableWorkerStdio extends Writable {
this[kWritableCallbacks] = [];
}

_write(chunk, encoding, cb) {
_writev(chunks, cb) {
this[kPort].postMessage({
type: messageTypes.STDIO_PAYLOAD,
stream: this[kName],
chunk,
encoding
chunks: chunks.map(({ chunk, encoding }) => ({ chunk, encoding }))
});
this[kWritableCallbacks].push(cb);
if (this[kPort][kWaitingStreams]++ === 0)
Expand All @@ -222,7 +221,7 @@ class WritableWorkerStdio extends Writable {
this[kPort].postMessage({
type: messageTypes.STDIO_PAYLOAD,
stream: this[kName],
chunk: null
chunks: [ { chunk: null, encoding: '' } ]
});
cb();
}
Expand Down

0 comments on commit 64cae13

Please sign in to comment.