From eec453ba91fce1f2a5bf6a007eeaed7797a38b68 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 6 Apr 2023 14:29:15 -0400 Subject: [PATCH] *await on the update being sent, and the update getting received --- src/index.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index a801dc4..a856f89 100644 --- a/src/index.ts +++ b/src/index.ts @@ -199,7 +199,8 @@ export class Socket extends Client { this.userData = null; const mux = Protomux.from(this); - let updateDone = defer(); + let updateSent = defer(); + let updateReceived = defer(); const setup = defer(); const [update] = this.connectModule( @@ -207,8 +208,8 @@ export class Socket extends Client { { id: this.id }, async (data: any) => { if (data === true) { - updateDone.resolve(); - updateDone = defer(); + updateSent.resolve(); + updateSent = defer(); return; } @@ -234,10 +235,10 @@ export class Socket extends Client { } }); mux._free = mux._free.filter((item: any) => item !== undefined); - update(true); this.syncMutex.release(); setup.resolve(); + updateReceived.resolve(); } ); @@ -247,7 +248,11 @@ export class Socket extends Client { local: Object.keys(mux._local), free: mux._free, }); - await updateDone.promise; + + updateReceived = defer(); + + await updateSent.promise; + await updateReceived.promise; }; mux.syncState = send.bind(undefined, mux); await setup.promise;