fix: race condition

This commit is contained in:
cha0s 2024-11-16 06:29:31 -06:00
parent 51edbec463
commit bfe9e427b9
3 changed files with 9 additions and 0 deletions

View File

@ -4,6 +4,9 @@ export default class LocalClient extends Client {
server = null;
async connect() {
await super.connect();
if (!this.connected) {
return;
}
this.server = new Worker(
new URL('../server/worker.js', import.meta.url),
{type: 'module'},

View File

@ -4,6 +4,9 @@ export default class RemoteClient extends Client {
socket = null;
async connect(host) {
await super.connect();
if (!this.connected) {
return;
}
this.socket = new WebSocket(`//${host}/silphius`);
this.socket.binaryType = 'arraybuffer';
this.socket.addEventListener('message', (event) => {

View File

@ -6,6 +6,7 @@ import {decode, encode} from '@/silphius/net/packets/index.js';
import {Flow} from './constants.js';
export default class Client {
connected = true;
emitter = new EventEmitter();
interpolator = null;
predictor = null;
@ -71,6 +72,7 @@ export default class Client {
}
});
}
this.connected = true;
}
disconnect() {
if (CLIENT_INTERPOLATION) {
@ -81,6 +83,7 @@ export default class Client {
this.predictor?.terminate();
this.predictor = null;
}
this.connected = false;
}
receive(packed) {
this.throughput.$$down += packed.byteLength;