Skip to content

Commit debfc36

Browse files
committed
Centralize timer cleanup
1 parent 20f3c6a commit debfc36

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/js/msp.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,6 @@ const MSP = {
461461
return;
462462
}
463463

464-
// Clear the existing timer before retry
465-
clearTimeout(requestObj.timer);
466-
467464
serial.send(bufferOut, (sendInfo) => {
468465
if (sendInfo.bytesSent === bufferOut.byteLength) {
469466
requestObj.timer = setTimeout(() => {
@@ -480,6 +477,11 @@ const MSP = {
480477
},
481478

482479
_removeRequestFromCallbacks(requestObj) {
480+
// Clear the timer if it exists
481+
if (requestObj.timer) {
482+
clearTimeout(requestObj.timer);
483+
}
484+
483485
const index = this.callbacks.indexOf(requestObj);
484486
if (index > -1) {
485487
this.callbacks.splice(index, 1);

0 commit comments

Comments
 (0)