switch interval to timeout

This commit is contained in:
Elijah 2023-12-10 16:03:18 -05:00
parent 49728dc841
commit 1adac4f982

View file

@ -99,8 +99,8 @@ export default class VM {
return; return;
} }
var msg = msgpack.decode(this.#currentChunk!) as protocol.ProtocolMessage; var msg = msgpack.decode(this.#currentChunk!) as protocol.ProtocolMessage;
if (this.#nopTimeout) clearInterval(this.#nopTimeout); if (this.#nopTimeout) clearTimeout(this.#nopTimeout);
this.#nopTimeout = setInterval(() => this.#nopTimeoutFunc(), 5000); this.#nopTimeout = setTimeout(() => this.#nopTimeoutFunc(), 5000);
if (!this.isConnectedToVM) { if (!this.isConnectedToVM) {
log("INFO", `Got connection to VM at ${this.#id}`); log("INFO", `Got connection to VM at ${this.#id}`);
if (this.#messageQueue.size > 0) this.messageQueueLoop(); if (this.#messageQueue.size > 0) this.messageQueueLoop();
@ -120,9 +120,10 @@ export default class VM {
Operation: protocol.ProtocolOperation.NOP Operation: protocol.ProtocolOperation.NOP
}); });
this.#noNop = true; this.#noNop = true;
setTimeout(() => this.#nopTimeoutFunc(), 5000);
} else { } else {
this.isConnectedToVM = false; this.isConnectedToVM = false;
clearInterval(this.#nopTimeout!); clearTimeout(this.#nopTimeout!);
log("INFO", `Connection to VM at ${this.#id} timed out`); log("INFO", `Connection to VM at ${this.#id} timed out`);
} }
} }