diff --git a/lib/internal/cluster/utils.js b/lib/internal/cluster/utils.js index ba72ff90945d3c..94b82d039a098a 100644 --- a/lib/internal/cluster/utils.js +++ b/lib/internal/cluster/utils.js @@ -7,7 +7,7 @@ module.exports = { handles: {} // Used in tests. }; -const callbacks = {}; +const callbacks = new Map(); var seq = 0; function sendHelper(proc, message, handle, cb) { @@ -18,7 +18,7 @@ function sendHelper(proc, message, handle, cb) { message = util._extend({ cmd: 'NODE_CLUSTER' }, message); if (typeof cb === 'function') - callbacks[seq] = cb; + callbacks.set(seq, cb); message.seq = seq; seq += 1; @@ -34,9 +34,13 @@ function internal(worker, cb) { var fn = cb; - if (message.ack !== undefined && callbacks[message.ack] !== undefined) { - fn = callbacks[message.ack]; - delete callbacks[message.ack]; + if (message.ack !== undefined) { + const callback = callbacks.get(message.ack); + + if (callback !== undefined) { + fn = callback; + callbacks.delete(message.ack); + } } fn.apply(worker, arguments);