Skip to content

Commit b122e83

Browse files
committed
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.
1 parent f392ac0 commit b122e83

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/internal/cluster/child.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,13 @@ cluster._getServer = function(obj, options, cb) {
101101
if (typeof obj._setServerData === 'function')
102102
obj._setServerData(reply.data);
103103

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

110113
obj.once('listening', () => {
@@ -129,7 +132,7 @@ function removeIndexesKey(indexesKey, index) {
129132
}
130133

131134
// Shared listen socket.
132-
function shared(message, handle, indexesKey, index, cb) {
135+
function shared(message, { handle, indexesKey, index }, cb) {
133136
const key = message.key;
134137
// Monkey-patch the close() method so we can keep track of when it's
135138
// closed. Avoids resource leaks when the handle is short-lived.
@@ -146,8 +149,8 @@ function shared(message, handle, indexesKey, index, cb) {
146149
cb(message.errno, handle);
147150
}
148151

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

0 commit comments

Comments
 (0)