This should not reject with ScriptDeath, the script is not being killed. Just 'undefined' isn't great either so left a TODO about improving it

This commit is contained in:
Heikki Aitakangas 2022-02-13 21:53:23 +02:00
parent a578763b89
commit 4fd55f099b

@ -4,8 +4,10 @@ import { ScriptDeath } from "./Netscript/ScriptDeath";
import { WorkerScript } from "./Netscript/WorkerScript"; import { WorkerScript } from "./Netscript/WorkerScript";
export function netscriptDelay(time: number, workerScript: WorkerScript): Promise<void> { export function netscriptDelay(time: number, workerScript: WorkerScript): Promise<void> {
if (workerScript.delayReject) // Cancel any pre-existing netscriptDelay'ed function call
workerScript.delayReject(new ScriptDeath(workerScript)); // TODO: the rejection almost certainly ends up in the uncaught rejection handler.
// Maybe reject with a stack-trace'd error message?
if (workerScript.delayReject) workerScript.delayReject();
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
workerScript.delay = window.setTimeout(() => { workerScript.delay = window.setTimeout(() => {