mirror of
https://github.com/nodejs/node.git
synced 2025-05-04 04:43:16 +00:00

Fixed comment for the description of INTERNAL_PREFIX in child_process whereas the value is present in the internal/child_process.js. PR-URL: https://github.com/nodejs/node/pull/39308 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
52 lines
1.0 KiB
JavaScript
52 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
ReflectApply,
|
|
SafeMap,
|
|
} = primordials;
|
|
|
|
module.exports = {
|
|
sendHelper,
|
|
internal
|
|
};
|
|
|
|
const callbacks = new SafeMap();
|
|
let seq = 0;
|
|
|
|
function sendHelper(proc, message, handle, cb) {
|
|
if (!proc.connected)
|
|
return false;
|
|
|
|
// Mark message as internal. See INTERNAL_PREFIX
|
|
// in lib/internal/child_process.js
|
|
message = { cmd: 'NODE_CLUSTER', ...message, seq };
|
|
|
|
if (typeof cb === 'function')
|
|
callbacks.set(seq, cb);
|
|
|
|
seq += 1;
|
|
return proc.send(message, handle);
|
|
}
|
|
|
|
// Returns an internalMessage listener that hands off normal messages
|
|
// to the callback but intercepts and redirects ACK messages.
|
|
function internal(worker, cb) {
|
|
return function onInternalMessage(message, handle) {
|
|
if (message.cmd !== 'NODE_CLUSTER')
|
|
return;
|
|
|
|
let fn = cb;
|
|
|
|
if (message.ack !== undefined) {
|
|
const callback = callbacks.get(message.ack);
|
|
|
|
if (callback !== undefined) {
|
|
fn = callback;
|
|
callbacks.delete(message.ack);
|
|
}
|
|
}
|
|
|
|
ReflectApply(fn, worker, arguments);
|
|
};
|
|
}
|