From e9028eb646c2b131969167b833a045d642bd3f2c Mon Sep 17 00:00:00 2001 From: Yash Ladha Date: Wed, 23 Dec 2020 18:01:05 +0530 Subject: [PATCH] cluster: restructure to same prototype for cluster child Since `rr` and `shared` both belongs to the same prototype declaration and differes only in the handler declaration, this can be abstracted to a same type of function arguments passing. PR-URL: https://github.com/nodejs/node/pull/36610 Reviewed-By: James M Snell --- lib/internal/cluster/child.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/internal/cluster/child.js b/lib/internal/cluster/child.js index 24db07f118befa..899038735c7968 100644 --- a/lib/internal/cluster/child.js +++ b/lib/internal/cluster/child.js @@ -100,10 +100,13 @@ cluster._getServer = function(obj, options, cb) { if (typeof obj._setServerData === 'function') obj._setServerData(reply.data); - if (handle) - shared(reply, handle, indexesKey, index, cb); // Shared listen socket. - else - rr(reply, indexesKey, index, cb); // Round-robin. + if (handle) { + // Shared listen socket + shared(reply, { handle, indexesKey, index }, cb); + } else { + // Round-robin. + rr(reply, { indexesKey, index }, cb); + } }); obj.once('listening', () => { @@ -128,7 +131,7 @@ function removeIndexesKey(indexesKey, index) { } // Shared listen socket. -function shared(message, handle, indexesKey, index, cb) { +function shared(message, { handle, indexesKey, index }, cb) { const key = message.key; // Monkey-patch the close() method so we can keep track of when it's // closed. Avoids resource leaks when the handle is short-lived. @@ -145,8 +148,8 @@ function shared(message, handle, indexesKey, index, cb) { cb(message.errno, handle); } -// Round-robin. Primary distributes handles across workers. -function rr(message, indexesKey, index, cb) { +// Round-robin. Master distributes handles across workers. +function rr(message, { indexesKey, index }, cb) { if (message.errno) return cb(message.errno, null);