*Bug fix and improve response handling

This commit is contained in:
Derrick Hammer 2022-09-19 08:11:54 -04:00
parent b25706e8ac
commit ce3fbcad0b
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 4 deletions

View File

@ -150,21 +150,31 @@ function handleListenSocketEvent(aq: ActiveQuery) {
return; return;
} }
let responded = false;
const respond = () => {
if (responded) {
return;
}
responded = true;
aq.respond();
};
const cb = (data: Buffer) => { const cb = (data: Buffer) => {
aq.sendUpdate(data); aq.sendUpdate(data);
}; };
socket.on(event, cb); socket.on(event, cb);
socket.on("close", () => { socket.on("close", () => {
socket.off(socket, cb); socket.off(event, cb);
aq.respond(); respond();
}); });
aq.setReceiveUpdate?.((data: any) => { aq.setReceiveUpdate?.((data: any) => {
switch (data?.action) { switch (data?.action) {
case "off": case "off":
socket.off(socket, cb); socket.off(event, cb);
aq.respond(); respond();
break; break;
} }
}); });