1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-26 01:35:28 +03:00

Centralize timer cleanup

This commit is contained in:
Mark Haslinghuis 2025-06-11 02:29:18 +02:00
parent 4d3f7b1c5f
commit 1a30f95176

View file

@ -461,9 +461,6 @@ const MSP = {
return; return;
} }
// Clear the existing timer before retry
clearTimeout(requestObj.timer);
serial.send(bufferOut, (sendInfo) => { serial.send(bufferOut, (sendInfo) => {
if (sendInfo.bytesSent === bufferOut.byteLength) { if (sendInfo.bytesSent === bufferOut.byteLength) {
requestObj.timer = setTimeout(() => { requestObj.timer = setTimeout(() => {
@ -480,6 +477,11 @@ const MSP = {
}, },
_removeRequestFromCallbacks(requestObj) { _removeRequestFromCallbacks(requestObj) {
// Clear the timer if it exists
if (requestObj.timer) {
clearTimeout(requestObj.timer);
}
const index = this.callbacks.indexOf(requestObj); const index = this.callbacks.indexOf(requestObj);
if (index > -1) { if (index > -1) {
this.callbacks.splice(index, 1); this.callbacks.splice(index, 1);