forked from svrjs/svrjs
Added process.singleThreaded flag.
This commit is contained in:
parent
a3e4ee2328
commit
7a658613fe
2 changed files with 204 additions and 198 deletions
|
@ -1,6 +1,5 @@
|
|||
const http = require("http");
|
||||
const fs = require("fs");
|
||||
const cluster = require("./utils/clusterBunShim.js"); // Cluster module with shim for Bun
|
||||
//const generateErrorStack = require("./utils/generateErrorStack.js");
|
||||
const getOS = require("./utils/getOS.js");
|
||||
const svrjsInfo = require("../svrjs.json");
|
||||
|
@ -20,6 +19,10 @@ if (!fs.existsSync(__dirname + "/log")) fs.mkdirSync(__dirname + "/log");
|
|||
if (!fs.existsSync(__dirname + "/mods")) fs.mkdirSync(__dirname + "/mods");
|
||||
if (!fs.existsSync(__dirname + "/temp")) fs.mkdirSync(__dirname + "/temp");
|
||||
|
||||
// TODO: process.singleThreaded flag
|
||||
process.singleThreaded = true;
|
||||
const cluster = require("./utils/clusterBunShim.js"); // Cluster module with shim for Bun
|
||||
|
||||
const serverconsoleConstructor = require("./utils/serverconsole.js");
|
||||
|
||||
let inspectorURL = undefined;
|
||||
|
|
|
@ -3,16 +3,18 @@ const os = require("os");
|
|||
const path = require("path");
|
||||
|
||||
let cluster = {};
|
||||
try {
|
||||
|
||||
if (!process.singleThreaded) {
|
||||
try {
|
||||
// Import cluster module
|
||||
cluster = require("cluster");
|
||||
} catch (err) {
|
||||
} catch (err) {
|
||||
// Clustering is not supported!
|
||||
}
|
||||
}
|
||||
|
||||
// Cluster & IPC shim for Bun
|
||||
// Cluster & IPC shim for Bun
|
||||
|
||||
cluster.bunShim = function () {
|
||||
cluster.bunShim = function () {
|
||||
cluster.isMaster = !process.env.NODE_UNIQUE_ID;
|
||||
cluster.isPrimary = cluster.isMaster;
|
||||
cluster.isWorker = !cluster.isMaster;
|
||||
|
@ -213,18 +215,19 @@ cluster.bunShim = function () {
|
|||
cluster._workersCounter++;
|
||||
return newWorker;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
if (
|
||||
if (
|
||||
process.isBun &&
|
||||
(cluster.isMaster === undefined ||
|
||||
(cluster.isMaster && process.env.NODE_UNIQUE_ID))
|
||||
) {
|
||||
) {
|
||||
cluster.bunShim();
|
||||
}
|
||||
|
||||
// Shim cluster.isPrimary field
|
||||
if (cluster.isPrimary === undefined && cluster.isMaster !== undefined)
|
||||
cluster.isPrimary = cluster.isMaster;
|
||||
}
|
||||
|
||||
// Shim cluster.isPrimary field
|
||||
if (cluster.isPrimary === undefined && cluster.isMaster !== undefined)
|
||||
cluster.isPrimary = cluster.isMaster;
|
||||
|
||||
module.exports = cluster;
|
||||
|
|
Reference in a new issue