*If for some reason we responded by the time we try to send an update, just abort
This commit is contained in:
parent
86a3881cfb
commit
41751c7d2b
10
src/index.ts
10
src/index.ts
|
@ -150,7 +150,11 @@ function handleSocketListenEvent(aq: ActiveQuery) {
|
||||||
aq.respond();
|
aq.respond();
|
||||||
};
|
};
|
||||||
|
|
||||||
const cb = (data: Buffer) => {
|
const cb = async (data: Buffer) => {
|
||||||
|
await socket.mutex?.waitForUnlock();
|
||||||
|
if (responded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
aq.sendUpdate(data);
|
aq.sendUpdate(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -184,7 +188,7 @@ function handleCloseSocketEvent(aq: ActiveQuery) {
|
||||||
aq.respond();
|
aq.respond();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleWriteSocketEvent(aq: ActiveQuery) {
|
async function handleWriteSocketEvent(aq: ActiveQuery) {
|
||||||
const socket = validateConnection(aq);
|
const socket = validateConnection(aq);
|
||||||
|
|
||||||
if (!socket) {
|
if (!socket) {
|
||||||
|
@ -197,6 +201,8 @@ function handleWriteSocketEvent(aq: ActiveQuery) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await socket.mutex?.waitForUnlock();
|
||||||
|
|
||||||
socket.write(message);
|
socket.write(message);
|
||||||
|
|
||||||
aq.respond();
|
aq.respond();
|
||||||
|
|
Loading…
Reference in New Issue