Initial commit for converting workerScripts pool to Map data structure

This commit is contained in:
danielyxie
2019-06-19 01:03:08 -07:00
parent 931de230ae
commit 821725cf4d
4 changed files with 64 additions and 3 deletions
+14 -1
View File
@@ -80,6 +80,12 @@ export class WorkerScript {
*/
output: string = "";
/**
* Process ID. Must be an integer. Used for efficient script
* killing and removal.
*/
pid: number;
/**
* Script's Static RAM usage. Equivalent to underlying script's RAM usage
*/
@@ -100,10 +106,17 @@ export class WorkerScript {
*/
serverIp: string;
constructor(runningScriptObj: RunningScript, nsFuncsGenerator?: (ws: WorkerScript) => object) {
constructor(runningScriptObj: RunningScript, pid: number, nsFuncsGenerator?: (ws: WorkerScript) => object) {
this.name = runningScriptObj.filename;
this.serverIp = runningScriptObj.server;
const sanitizedPid = Math.round(pid);
if (typeof sanitizedPid !== "number" || isNaN(sanitizedPid)) {
throw new Error(`Invalid PID when constructing WorkerScript: ${pid}`);
}
this.pid = sanitizedPid;
runningScriptObj.pid = sanitizedPid;
// Get the underlying script's code
const server = AllServers[this.serverIp];
if (server == null) {