BUGFIX: Fix writePort() error where deconstructing the Port class caused the reduce() function to lose its 'this' reference (#1037)

This commit is contained in:
Justin 2024-01-15 06:14:13 -05:00 committed by GitHub
parent 157ff8ea88
commit 39c5a356b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -49,10 +49,10 @@ export function writePort(n: PortNumber, value: unknown): PortData | null {
`port.write: Tried to write type ${typeof value}. Only string and number types may be written to ports.`, `port.write: Tried to write type ${typeof value}. Only string and number types may be written to ports.`,
); );
} }
const { data, resolve } = getPort(n); const port = getPort(n);
data.push(value); port.data.push(value);
resolve(); port.resolve();
if (data.length > Settings.MaxPortCapacity) return data.shift() as PortData; if (port.data.length > Settings.MaxPortCapacity) return port.data.shift() as PortData;
return null; return null;
} }
@ -62,10 +62,10 @@ export function tryWritePort(n: PortNumber, value: unknown): boolean {
`port.write: Tried to write type ${typeof value}. Only string and number types may be written to ports.`, `port.write: Tried to write type ${typeof value}. Only string and number types may be written to ports.`,
); );
} }
const { data, resolve } = getPort(n); const port = getPort(n);
if (data.length >= Settings.MaxPortCapacity) return false; if (port.data.length >= Settings.MaxPortCapacity) return false;
data.push(value); port.data.push(value);
resolve(); port.resolve();
return true; return true;
} }