*await on the update being sent, and the update getting received
This commit is contained in:
parent
c2ebdc00b9
commit
eec453ba91
15
src/index.ts
15
src/index.ts
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue