• Thanks for stripping this down...

    I just stripped it right back and there's no problem. It turns out the issue is how timers are handled when a timer is added within a timer callback.

    Try this:

    setInterval(function () {
      if (BTN1.read()) setTimeout(function(){},0);
    }, 100);
    setInterval(function() {
      digitalPulse(LED1,1,10);
    }, 1000);
    

    LED1 should flash every second. However if you press BTN1 it'll just stop!

    I've filed an issue for this at https://github.com/espruino/Espruino/issues/1829 and I'll try and get it fixed ASAP.

    However you could fix it as-is by removing your setTimeout(function () { .... }, 0) line - I'm not entirely sure about the reasoning for that anyway?

About

Avatar for Gordon @Gordon started