mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
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:
1 parent
d81b9af1fc
commit
e9028eb646
1 file changed
+10
-7
@@ -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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user