Skip to content

Commit 2df7b0d

Browse files
committed
Fix issue with the callback being called too often
1 parent 4a3c921 commit 2df7b0d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

core/serial.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ To add a new serial device, you must add an object to
223223
return;
224224
}
225225
var txItem = connection.txDataQueue[0];
226-
uart.writeProgress(txItem.maxLength - txItem.data.length, txItem.maxLength);
227-
connection.updateProgress(txItem.maxLength - txItem.data.length, txItem.maxLength);
226+
uart.writeProgress(txItem.maxLength - (txItem.data?txItem.data.length:0), txItem.maxLength);
227+
connection.updateProgress(txItem.maxLength - (txItem.data?txItem.data.length:0), txItem.maxLength);
228228
if (txItem.data.length <= connection.chunkSize) {
229229
chunk = txItem.data;
230230
txItem.data = undefined;
@@ -759,10 +759,11 @@ To add a new serial device, you must add an object to
759759
//console.log("serial: Sending block "+JSON.stringify(d)+", wait "+split.delay+"ms");
760760
Espruino.Core.Serial.connection.write(d, function() { // write data, but the callback returns a promise that delays
761761
return new Promise(resolve => setTimeout(function() {
762-
if (isLast && writeData.showStatus)
762+
if (isLast && writeData.showStatus) {
763763
Espruino.Core.Status.setStatus("Sent");
764-
if (writeData.callback)
765-
writeData.callback();
764+
if (writeData.callback)
765+
writeData.callback();
766+
}
766767
resolve();
767768
}, split.delay));
768769
});

0 commit comments

Comments
 (0)