*await on the update being sent, and the update getting received

This commit is contained in:
Derrick Hammer 2023-04-06 14:29:15 -04:00
parent c2ebdc00b9
commit eec453ba91
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 5 deletions

View File

@ -199,7 +199,8 @@ export class Socket extends Client {
this.userData = null; this.userData = null;
const mux = Protomux.from(this); const mux = Protomux.from(this);
let updateDone = defer(); let updateSent = defer();
let updateReceived = defer();
const setup = defer(); const setup = defer();
const [update] = this.connectModule( const [update] = this.connectModule(
@ -207,8 +208,8 @@ export class Socket extends Client {
{ id: this.id }, { id: this.id },
async (data: any) => { async (data: any) => {
if (data === true) { if (data === true) {
updateDone.resolve(); updateSent.resolve();
updateDone = defer(); updateSent = defer();
return; return;
} }
@ -234,10 +235,10 @@ export class Socket extends Client {
} }
}); });
mux._free = mux._free.filter((item: any) => item !== undefined); mux._free = mux._free.filter((item: any) => item !== undefined);
update(true);
this.syncMutex.release(); this.syncMutex.release();
setup.resolve(); setup.resolve();
updateReceived.resolve();
} }
); );
@ -247,7 +248,11 @@ export class Socket extends Client {
local: Object.keys(mux._local), local: Object.keys(mux._local),
free: mux._free, free: mux._free,
}); });
await updateDone.promise;
updateReceived = defer();
await updateSent.promise;
await updateReceived.promise;
}; };
mux.syncState = send.bind(undefined, mux); mux.syncState = send.bind(undefined, mux);
await setup.promise; await setup.promise;