Skip to content

Commit e9028eb

Browse files
yashLadhadanielleadams
authored andcommitted
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: #36610 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d81b9af commit e9028eb

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/internal/cluster/child.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,13 @@ cluster._getServer = function(obj, options, cb) {
100100
if (typeof obj._setServerData === 'function')
101101
obj._setServerData(reply.data);
102102

103-
if (handle)
104-
shared(reply, handle, indexesKey, index, cb); // Shared listen socket.
105-
else
106-
rr(reply, indexesKey, index, cb); // Round-robin.
103+
if (handle) {
104+
// Shared listen socket
105+
shared(reply, { handle, indexesKey, index }, cb);
106+
} else {
107+
// Round-robin.
108+
rr(reply, { indexesKey, index }, cb);
109+
}
107110
});
108111

109112
obj.once('listening', () => {
@@ -128,7 +131,7 @@ function removeIndexesKey(indexesKey, index) {
128131
}
129132

130133
// Shared listen socket.
131-
function shared(message, handle, indexesKey, index, cb) {
134+
function shared(message, { handle, indexesKey, index }, cb) {
132135
const key = message.key;
133136
// Monkey-patch the close() method so we can keep track of when it's
134137
// closed. Avoids resource leaks when the handle is short-lived.
@@ -145,8 +148,8 @@ function shared(message, handle, indexesKey, index, cb) {
145148
cb(message.errno, handle);
146149
}
147150

148-
// Round-robin. Primary distributes handles across workers.
149-
function rr(message, indexesKey, index, cb) {
151+
// Round-robin. Master distributes handles across workers.
152+
function rr(message, { indexesKey, index }, cb) {
150153
if (message.errno)
151154
return cb(message.errno, null);
152155

0 commit comments

Comments
 (0)