Skip to content

Commit

Permalink
child_process: remove nextTick on IPC message
Browse files Browse the repository at this point in the history
  • Loading branch information
mscdex committed Jun 13, 2017
1 parent c4fc7d9 commit def344b
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ function setupChannel(target, channel) {
}
chunks[0] = jsonBuffer + chunks[0];

var nextTick = false;
for (var i = 0; i < numCompleteChunks; i++) {
var message = JSON.parse(chunks[i]);

Expand All @@ -465,12 +464,11 @@ function setupChannel(target, channel) {
// that we deliver the handle with the right message however.
if (isInternal(message)) {
if (message.cmd === 'NODE_HANDLE')
handleMessage(message, recvHandle, true, false);
handleMessage(message, recvHandle, true);
else
handleMessage(message, undefined, true, false);
handleMessage(message, undefined, true);
} else {
handleMessage(message, undefined, false, nextTick);
nextTick = true;
handleMessage(message, undefined, false);
}
}
jsonBuffer = incompleteChunk;
Expand Down Expand Up @@ -532,7 +530,7 @@ function setupChannel(target, channel) {

// Convert handle object
obj.got.call(this, message, handle, function(handle) {
handleMessage(message.msg, handle, isInternal(message.msg), false);
handleMessage(message.msg, handle, isInternal(message.msg));
});
});

Expand Down Expand Up @@ -738,19 +736,12 @@ function setupChannel(target, channel) {
process.nextTick(finish);
};

function emit(event, message, handle) {
target.emit(event, message, handle);
}

function handleMessage(message, handle, internal, nextTick) {
function handleMessage(message, handle, internal) {
if (!target.channel)
return;

var eventName = (internal ? 'internalMessage' : 'message');
if (nextTick)
process.nextTick(emit, eventName, message, handle);
else
target.emit(eventName, message, handle);
target.emit(eventName, message, handle);
}

channel.readStart();
Expand Down

0 comments on commit def344b

Please sign in to comment.