(primaryInitiated)
| 252 | } |
| 253 | |
| 254 | function _disconnect(primaryInitiated) { |
| 255 | this.exitedAfterDisconnect = true; |
| 256 | let waitingCount = 1; |
| 257 | |
| 258 | function checkWaitingCount() { |
| 259 | waitingCount--; |
| 260 | |
| 261 | if (waitingCount === 0) { |
| 262 | // If disconnect is worker initiated, wait for ack to be sure |
| 263 | // exitedAfterDisconnect is properly set in the primary, otherwise, if |
| 264 | // it's primary initiated there's no need to send the |
| 265 | // exitedAfterDisconnect message |
| 266 | if (primaryInitiated) { |
| 267 | process.disconnect(); |
| 268 | } else { |
| 269 | send({ act: 'exitedAfterDisconnect' }, () => process.disconnect()); |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | for (const handle of handles.values()) { |
| 275 | waitingCount++; |
| 276 | |
| 277 | if (handle[owner_symbol]) |
| 278 | handle[owner_symbol].close(checkWaitingCount); |
| 279 | else |
| 280 | handle.close(checkWaitingCount); |
| 281 | } |
| 282 | |
| 283 | handles.clear(); |
| 284 | checkWaitingCount(); |
| 285 | } |
| 286 | |
| 287 | // Extend generic Worker with methods specific to worker processes. |
| 288 | Worker.prototype.disconnect = function() { |
nothing calls this directly
no test coverage detected