*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;
}
let responded = false;
const respond = () => {
if (responded) {
return;
}
responded = true;
aq.respond();
};
const cb = (data: Buffer) => {
aq.sendUpdate(data);
};
socket.on(event, cb);
socket.on("close", () => {
socket.off(socket, cb);
aq.respond();
socket.off(event, cb);
respond();
});
aq.setReceiveUpdate?.((data: any) => {
switch (data?.action) {
case "off":
socket.off(socket, cb);
aq.respond();
socket.off(event, cb);
respond();
break;
}
});