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 <jasnell@gmail.com>
This commit is contained in:
Yash Ladha authored and Danielle Adams committed 2021-03-16 08:55:16 -04:00
1 parent d81b9af1fc
commit e9028eb646
1 file changed
+10 -7
+10 -7
View File
@@ -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);