Skip to content

Commit

Permalink
cluster: restructure to same prototype for cluster child
Browse files Browse the repository at this point in the history
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: #36610
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
yashLadha authored and danielleadams committed Mar 16, 2021
1 parent d81b9af commit e9028eb
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/internal/cluster/child.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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.
Expand All @@ -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);

Expand Down

0 comments on commit e9028eb

Please sign in to comment.