Merge pull request #1444 from danielyxie/dev

write can be awaited in order to wait for the ram calculation to go t…
This commit is contained in:
hydroflame 2021-10-08 14:06:06 -04:00 committed by GitHub
commit 09e1ee8f6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 7 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -2321,17 +2321,16 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
// Create a new script
script = new Script(fn, data, server.hostname, server.scripts);
server.scripts.push(script);
return true;
return script.updateRamUsage(server.scripts);
}
mode === "w" ? (script.code = data) : (script.code += data);
script.updateRamUsage(server.scripts);
script.markUpdated();
return script.updateRamUsage(server.scripts);
} else {
// Write to text file
const txtFile = getTextFile(fn, server);
if (txtFile == null) {
createTextFile(fn, data, server);
return true;
return Promise.resolve();
}
if (mode === "w") {
txtFile.write(data);
@ -2339,7 +2338,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
txtFile.append(data);
}
}
return true;
return Promise.resolve();
} else {
throw makeRuntimeErrorMsg("write", `Invalid argument: ${port}`);
}

@ -109,6 +109,7 @@ export class Script {
if (res > 0) {
this.ramUsage = roundToTwo(res);
}
this.markUpdated();
}
// Serialize the current object to a JSON save state