Hi Gordon,
I found the issue in the https://www.puck-js.com/puck.js code I believe. I've made some comments below.
connection.write = function(data, callback) { // **** This is pushing callback as null **** if (data) txDataQueue.push({data:data,callback:callback}); // *********************** if (connection.isOpen && !connection.txInProgress) writeChunk(); function writeChunk() { var chunk; if (!txDataQueue.length) return; var txItem = txDataQueue[0]; if (txItem.data.length <= CHUNKSIZE) { chunk = txItem.data; txItem.data = undefined; } else { chunk = txItem.data.substr(0,CHUNKSIZE); txItem.data = txItem.data.substr(CHUNKSIZE); } connection.txInProgress = true; log("BT> Sending "+ JSON.stringify(chunk)); txCharacteristic.writeValue(str2ab(chunk)).then(function() { log("BT> Sent"); if (!txItem.data) { txDataQueue.shift(); // **** This is calling the null callback function and throwing an Error. **** txItem.callback(); // *************************** } connection.txInProgress = false; writeChunk(); }).catch(function(error) { log('BT> SEND ERROR: ' + error); txDataQueue = []; // **** The error is being caught and the connection is being closed. **** connection.close(); // ******************** }); } };
Like you said it's an easy fix to only call the callback if one is passed.
@alexjfno1 started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi Gordon,
I found the issue in the https://www.puck-js.com/puck.js code I believe. I've made some comments below.
Like you said it's an easy fix to only call the callback if one is passed.