chore: update cluster shim
This commit is contained in:
parent
7895085922
commit
6b1df975d7
2 changed files with 18 additions and 18 deletions
|
@ -1,4 +1,4 @@
|
|||
const cluster = require("./utils/clusterBunShim.js"); // Cluster shim for Bun
|
||||
const cluster = require("./utils/clusterShim.js"); // Cluster shim for Bun and Deno
|
||||
const { add } = require("./utils/helper.js"); // Require the addition module
|
||||
const modInfo = require("../modInfo.json"); // SVR.JS mod information
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ if (!process.singleThreaded) {
|
|||
// Clustering is not supported!
|
||||
}
|
||||
|
||||
// Cluster & IPC shim for Bun
|
||||
// Cluster & IPC shim for Bun and Deno
|
||||
|
||||
cluster.bunShim = () => {
|
||||
cluster.shim = () => {
|
||||
cluster.isMaster = !process.env.NODE_UNIQUE_ID;
|
||||
cluster.isPrimary = cluster.isMaster;
|
||||
cluster.isWorker = !cluster.isMaster;
|
||||
|
@ -29,7 +29,7 @@ if (!process.singleThreaded) {
|
|||
isDead: () => false,
|
||||
send: (message, ...params) => {
|
||||
process.send(message, ...params);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
if (!process.send) {
|
||||
|
@ -52,9 +52,9 @@ if (!process.singleThreaded) {
|
|||
? path.join(
|
||||
"\\\\?\\pipe",
|
||||
process.dirname,
|
||||
"temp/.W" + process.pid + ".ipc",
|
||||
"temp/.W" + process.pid + ".ipc"
|
||||
)
|
||||
: process.dirname + "/temp/.W" + process.pid + ".ipc",
|
||||
: process.dirname + "/temp/.W" + process.pid + ".ipc"
|
||||
);
|
||||
|
||||
process.send = (message) => {
|
||||
|
@ -64,12 +64,12 @@ if (!process.singleThreaded) {
|
|||
? path.join(
|
||||
"\\\\?\\pipe",
|
||||
process.dirname,
|
||||
"temp/.P" + process.pid + ".ipc",
|
||||
"temp/.P" + process.pid + ".ipc"
|
||||
)
|
||||
: process.dirname + "/temp/.P" + process.pid + ".ipc",
|
||||
() => {
|
||||
fakeIPCConnection.end(message);
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -92,7 +92,7 @@ if (!process.singleThreaded) {
|
|||
let command = newArguments.shift();
|
||||
let newWorker = child_process.spawn(command, newArguments, {
|
||||
env: newEnvironment,
|
||||
stdio: ["inherit", "inherit", "inherit", "ipc"],
|
||||
stdio: ["inherit", "inherit", "inherit", "ipc"]
|
||||
});
|
||||
|
||||
newWorker.process = newWorker;
|
||||
|
@ -126,7 +126,7 @@ if (!process.singleThreaded) {
|
|||
};
|
||||
|
||||
try {
|
||||
worker.send(undefined);
|
||||
if (process.isBun) worker.send(undefined);
|
||||
} catch (err) {
|
||||
if (err.message === "NOT IMPLEMENTED") {
|
||||
sendImplemented = false;
|
||||
|
@ -158,9 +158,9 @@ if (!process.singleThreaded) {
|
|||
? path.join(
|
||||
"\\\\?\\pipe",
|
||||
process.dirname,
|
||||
"temp/.P" + newWorker.process.pid + ".ipc",
|
||||
"temp/.P" + newWorker.process.pid + ".ipc"
|
||||
)
|
||||
: process.dirname + "/temp/.P" + newWorker.process.pid + ".ipc",
|
||||
: process.dirname + "/temp/.P" + newWorker.process.pid + ".ipc"
|
||||
);
|
||||
|
||||
// Cleanup when worker process exits
|
||||
|
@ -174,7 +174,7 @@ if (!process.singleThreaded) {
|
|||
fakeParam2,
|
||||
fakeParam3,
|
||||
fakeParam4,
|
||||
tries,
|
||||
tries
|
||||
) {
|
||||
if (!tries) tries = 0;
|
||||
|
||||
|
@ -185,12 +185,12 @@ if (!process.singleThreaded) {
|
|||
? path.join(
|
||||
"\\\\?\\pipe",
|
||||
process.dirname,
|
||||
"temp/.W" + newWorker.process.pid + ".ipc",
|
||||
"temp/.W" + newWorker.process.pid + ".ipc"
|
||||
)
|
||||
: process.dirname + "/temp/.W" + newWorker.process.pid + ".ipc",
|
||||
() => {
|
||||
fakeWorkerIPCConnection.end(message);
|
||||
},
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
if (tries > 50) throw err;
|
||||
|
@ -199,7 +199,7 @@ if (!process.singleThreaded) {
|
|||
fakeParam2,
|
||||
fakeParam3,
|
||||
fakeParam4,
|
||||
tries + 1,
|
||||
tries + 1
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@ -216,11 +216,11 @@ if (!process.singleThreaded) {
|
|||
};
|
||||
|
||||
if (
|
||||
process.isBun &&
|
||||
(process.isBun || (process.versions && process.versions.deno)) &&
|
||||
(cluster.isMaster === undefined ||
|
||||
(cluster.isMaster && process.env.NODE_UNIQUE_ID))
|
||||
) {
|
||||
cluster.bunShim();
|
||||
cluster.shim();
|
||||
}
|
||||
|
||||
// Shim cluster.isPrimary field
|
Loading…
Reference in a new issue