Skip to content

Commit 5586c3c

Browse files
committed
dgram: refactor to remove unreachable code
There is no need to ensure `cluster` loaded in `bindServerHandle` because it's already loaded before calling it. This PR makes `cluster` as an argument to remind developers that `cluster` needs to be loaded before calling this function.
1 parent aed17e9 commit 5586c3c

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

lib/dgram.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,7 @@ function bufferSize(self, size, buffer) {
199199
}
200200

201201
// Query primary process to get the server handle and utilize it.
202-
function bindServerHandle(self, options, errCb) {
203-
if (!cluster)
204-
cluster = require('cluster');
205-
202+
function bindServerHandle(cluster, self, options, errCb) {
206203
const state = self[kStateSymbol];
207204
cluster._getServer(self, options, (err, handle) => {
208205
if (err) {
@@ -266,7 +263,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
266263
cluster = require('cluster');
267264

268265
if (cluster.isWorker && !exclusive) {
269-
bindServerHandle(this, {
266+
bindServerHandle(cluster, this, {
270267
address: null,
271268
port: null,
272269
addressType: this.type,
@@ -335,7 +332,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
335332
flags |= UV_UDP_IPV6ONLY;
336333

337334
if (cluster.isWorker && !exclusive) {
338-
bindServerHandle(this, {
335+
bindServerHandle(cluster, this, {
339336
address: ip,
340337
port: port,
341338
addressType: this.type,

0 commit comments

Comments
 (0)