| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 16b2fb4 commit 4001dd2
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -85,7 +85,11 @@ const RECV_BUFFER = true; | |||
| 85 | 85 | const SEND_BUFFER = false; | |
| 86 | 86 | ||
| 87 | 87 | // Lazily loaded | |
| 88 | - let cluster = null; | ||
| 88 | + let _cluster = null; | ||
| 89 | + function lazyLoadCluster() { | ||
| 90 | + if (!_cluster) _cluster = require('cluster'); | ||
| 91 | + return _cluster; | ||
| 92 | + } | ||
| 89 | 93 | ||
| 90 | 94 | const errnoException = errors.errnoException; | |
| 91 | 95 | const exceptionWithHostPort = errors.exceptionWithHostPort; | |
@@ -200,8 +204,7 @@ function bufferSize(self, size, buffer) { | |||
| 200 | 204 | ||
| 201 | 205 | // Query primary process to get the server handle and utilize it. | |
| 202 | 206 | function bindServerHandle(self, options, errCb) { | |
| 203 | - if (!cluster) | ||
| 204 | - cluster = require('cluster'); | ||
| 207 | + const cluster = lazyLoadCluster(); | ||
| 205 | 208 | ||
| 206 | 209 | const state = self[kStateSymbol]; | |
| 207 | 210 | cluster._getServer(self, options, (err, handle) => { | |
@@ -262,8 +265,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) { | |||
| 262 | 265 | const exclusive = !!port.exclusive; | |
| 263 | 266 | const state = this[kStateSymbol]; | |
| 264 | 267 | ||
| 265 | - if (!cluster) | ||
| 266 | - cluster = require('cluster'); | ||
| 268 | + const cluster = lazyLoadCluster(); | ||
| 267 | 269 | ||
| 268 | 270 | if (cluster.isWorker && !exclusive) { | |
| 269 | 271 | bindServerHandle(this, { | |
@@ -325,8 +327,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) { | |||
| 325 | 327 | return; | |
| 326 | 328 | } | |
| 327 | 329 | ||
| 328 | - if (!cluster) | ||
| 329 | - cluster = require('cluster'); | ||
| 330 | + const cluster = lazyLoadCluster(); | ||
| 330 | 331 | ||
| 331 | 332 | let flags = 0; | |
| 332 | 333 | if (state.reuseAddr) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments