Skip to content

Commit 64cae13

Browse files
addaleaxcodebytere
authored andcommitted
worker: use _writev in internal communication
PR-URL: #33454 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent b0bce9b commit 64cae13

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

lib/internal/main/worker_thread.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ port.on('message', (message) => {
167167
CJSLoader.Module.runMain(filename);
168168
}
169169
} else if (message.type === STDIO_PAYLOAD) {
170-
const { stream, chunk, encoding } = message;
171-
process[stream].push(chunk, encoding);
170+
const { stream, chunks } = message;
171+
for (const { chunk, encoding } of chunks)
172+
process[stream].push(chunk, encoding);
172173
} else {
173174
assert(
174175
message.type === STDIO_WANTS_MORE_DATA,

lib/internal/worker.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,11 @@ class Worker extends EventEmitter {
243243
return this[kOnErrorMessage](message.error);
244244
case messageTypes.STDIO_PAYLOAD:
245245
{
246-
const { stream, chunk, encoding } = message;
247-
return this[kParentSideStdio][stream].push(chunk, encoding);
246+
const { stream, chunks } = message;
247+
const readable = this[kParentSideStdio][stream];
248+
for (const { chunk, encoding } of chunks)
249+
readable.push(chunk, encoding);
250+
return;
248251
}
249252
case messageTypes.STDIO_WANTS_MORE_DATA:
250253
{

lib/internal/worker/io.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,11 @@ class WritableWorkerStdio extends Writable {
206206
this[kWritableCallbacks] = [];
207207
}
208208

209-
_write(chunk, encoding, cb) {
209+
_writev(chunks, cb) {
210210
this[kPort].postMessage({
211211
type: messageTypes.STDIO_PAYLOAD,
212212
stream: this[kName],
213-
chunk,
214-
encoding
213+
chunks: chunks.map(({ chunk, encoding }) => ({ chunk, encoding }))
215214
});
216215
this[kWritableCallbacks].push(cb);
217216
if (this[kPort][kWaitingStreams]++ === 0)
@@ -222,7 +221,7 @@ class WritableWorkerStdio extends Writable {
222221
this[kPort].postMessage({
223222
type: messageTypes.STDIO_PAYLOAD,
224223
stream: this[kName],
225-
chunk: null
224+
chunks: [ { chunk: null, encoding: '' } ]
226225
});
227226
cb();
228227
}

0 commit comments

Comments
 (0)