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.`,
);
}
const { data, resolve } = getPort(n);
data.push(value);
resolve();
if (data.length > Settings.MaxPortCapacity) return data.shift() as PortData;
const port = getPort(n);
port.data.push(value);
port.resolve();
if (port.data.length > Settings.MaxPortCapacity) return port.data.shift() as PortData;
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.`,
);
}
const { data, resolve } = getPort(n);
if (data.length >= Settings.MaxPortCapacity) return false;
data.push(value);
resolve();
const port = getPort(n);
if (port.data.length >= Settings.MaxPortCapacity) return false;
port.data.push(value);
port.resolve();
return true;
}