Just to add, continuously rescheduling the same task using a setTimeout is (IMO) a bad idea for embedded things. What happens if something you didn't expect causes an exception? The whole thing will stop. It doesn't have to be network-related at all.
IMO something like this is a lot more straightforward.
var inProgress = false;
function doStuff() {
if (inProgress) console.log("Last transaction failed...");
inProgress = true;
http.get(..., function() {
inProgress = false;
});
}
setInterval(doStuff, 60000);
Although as you noted earlier it only really works if the period is greater than the socket timeout.
Also, the socket error printed to the console will almost certainly have come from idle processing, and won't affect the execution of any code. It just means your handler won't get called.
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.
Just to add, continuously rescheduling the same task using a
setTimeout
is (IMO) a bad idea for embedded things. What happens if something you didn't expect causes an exception? The whole thing will stop. It doesn't have to be network-related at all.IMO something like this is a lot more straightforward.
Although as you noted earlier it only really works if the period is greater than the socket timeout.
Also, the socket error printed to the console will almost certainly have come from idle processing, and won't affect the execution of any code. It just means your handler won't get called.