MISC: Switch port.nextWrite() from LIFO to FIFO (#965)

This commit is contained in:
LJ 2023-12-07 16:00:01 -07:00 committed by GitHub
parent 375cf453b3
commit 1ce0584b25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -44,7 +44,7 @@ export function writePort(n: PortNumber, value: unknown): PortData | null {
} }
const { data, resolvers } = getPort(n); const { data, resolvers } = getPort(n);
data.push(value); 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; if (data.length > Settings.MaxPortCapacity) return data.shift() as PortData;
return null; return null;
} }
@ -58,7 +58,7 @@ export function tryWritePort(n: PortNumber, value: unknown): boolean {
const { data, resolvers } = getPort(n); const { data, resolvers } = getPort(n);
if (data.length >= Settings.MaxPortCapacity) return false; if (data.length >= Settings.MaxPortCapacity) return false;
data.push(value); data.push(value);
while (resolvers.length > 0) resolvers.pop()?.(); for (const res of resolvers.splice(0, resolvers.length)) res();
return true; return true;
} }