From 1ce0584b252e649be32e5dfeb13c8262246999de Mon Sep 17 00:00:00 2001 From: LJ <23249107+LJNeon@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:00:01 -0700 Subject: [PATCH] MISC: Switch port.nextWrite() from LIFO to FIFO (#965) --- src/NetscriptPort.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NetscriptPort.ts b/src/NetscriptPort.ts index 81c3a8555..6f05c3fb5 100644 --- a/src/NetscriptPort.ts +++ b/src/NetscriptPort.ts @@ -44,7 +44,7 @@ export function writePort(n: PortNumber, value: unknown): PortData | null { } const { data, resolvers } = getPort(n); data.push(value); - while (resolvers.length > 0) resolvers.pop()?.(); + for (const res of resolvers.splice(0, resolvers.length)) res(); if (data.length > Settings.MaxPortCapacity) return data.shift() as PortData; return null; } @@ -58,7 +58,7 @@ export function tryWritePort(n: PortNumber, value: unknown): boolean { const { data, resolvers } = getPort(n); if (data.length >= Settings.MaxPortCapacity) return false; data.push(value); - while (resolvers.length > 0) resolvers.pop()?.(); + for (const res of resolvers.splice(0, resolvers.length)) res(); return true; }