Skip to content

Commit

Permalink
dgram: refactor to remove unreachable code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pd4d10 committed May 6, 2021
1 parent aed17e9 commit 5586c3c
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ function bufferSize(self, size, buffer) {
}

// Query primary process to get the server handle and utilize it.
function bindServerHandle(self, options, errCb) {
if (!cluster)
cluster = require('cluster');

function bindServerHandle(cluster, self, options, errCb) {
const state = self[kStateSymbol];
cluster._getServer(self, options, (err, handle) => {
if (err) {
Expand Down Expand Up @@ -266,7 +263,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
cluster = require('cluster');

if (cluster.isWorker && !exclusive) {
bindServerHandle(this, {
bindServerHandle(cluster, this, {
address: null,
port: null,
addressType: this.type,
Expand Down Expand Up @@ -335,7 +332,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
flags |= UV_UDP_IPV6ONLY;

if (cluster.isWorker && !exclusive) {
bindServerHandle(this, {
bindServerHandle(cluster, this, {
address: ip,
port: port,
addressType: this.type,
Expand Down

0 comments on commit 5586c3c

Please sign in to comment.