t message = { act: "queryServer", index, data: null, ...options }; if (message.address = address, obj._getServerData) message.data = obj._getServerData(); send(message, (reply, handle) => { if (typeof obj._setServerData === "function") obj._setServerData(reply.data); if (handle) shared(reply, { handle, indexesKey, index }, cb); else rr(reply, { indexesKey, index }, cb); }), obj.once("listening", () => { if (!indexes.has(indexesKey)) return; cluster.worker.state = "listening"; let address2 = obj.address(); message.act = "listening", message.port = address2 && address2.port || options.port, send(message); }); }; function removeIndexesKey(indexesKey, index) { let indexSet = indexes.get(indexesKey); if (!indexSet) return; if (indexSet.set.delete(index), indexSet.set.size === 0) indexes.delete(indexesKey); } function shared(message, { handle, indexesKey, index }, cb) { let key = message.key, close = handle.close; handle.close = function() { return send({ act: "close", key }), handles.delete(key), removeIndexesKey(indexesKey, index), close.@apply(handle, arguments); }, handles.set(key, handle), cb(message.errno, handle); } function rr(message, { indexesKey, index }, cb) { if (message.errno) return cb(message.errno, null); let key = message.key, fakeHandle = null; function ref() { if (!fakeHandle) fakeHandle = setInterval(noop, 2147483647); } function unref() { if (fakeHandle) clearInterval(fakeHandle), fakeHandle = null; } function listen(_backlog) { return 0; } function close() { if (key === @undefined) return; unref(), send({ act: "close", key }), handles.delete(key), removeIndexesKey(indexesKey, index), key = @undefined; } function getsockname(out) { if (key) ObjectAssign(out, message.sockname); return 0; } let handle = { close, listen, ref, unref }; if (handle.ref(), message.sockname) handle.getsockname = getsockname; handles.set(key, handle), cb(0, handle); } function onconnection(message, handle) { let key = message.key, server = handles.get(key), accepted = server !== @undefined; if (accepted && server[owner_symbol]) { let self = server[owner_symbol]; if (self.maxConnections != null && self._connections >= self.maxConnections) accepted = !1; } if (send({ ack: message.seq, accepted }), accepted) server.onconnection(0, handle); else handle.close(); } function send(message, cb) { return sendHelper(message, null, cb); } Worker.prototype.disconnect = function() { if (this.state !== "disconnecting" && this.state !== "destroying") this.state = "disconnecting", this._disconnect(); return this; }; Worker.prototype._disconnect = function(primaryInitiated) { this.exitedAfterDisconnect = !0; let waitingCount = 1; function checkWaitingCount() { if (waitingCount--, waitingCount === 0) if (primaryInitiated) process.disconnect(); else send({ act: "exitedAfterDisconnect" }, () => process.disconnect()); } handles.forEach((handle) => { if (waitingCount++, handle[owner_symbol]) handle[owner_symbol].close(checkWaitingCount); else handle.close(checkWaitingCount); }), handles.clear(), checkWaitingCount(); }; Worker.prototype.destroy = function() { if (this.state === "destroying") return; if (this.exitedAfterDisconnect = !0, !this.isConnected()) process.exit(0); else this.state = "destroying", send({ act: "exitedAfterDisconnect" }, () => process.disconnect()), process.once("disconnect", () => process.exit(0)); }; return $})