You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • I still think there's a problem there. If you run planChime once and wait, then lets say chimeTimer gets set to the number 2. Now the setTimeout callback is called and the timer is finished, but chimeTimer is still set to 2.

    Maybe now some other code calls setTimeout and gets a new timer with ID 2.

    Next time you call planChime it'll then disable that new (unrelated) timeout - so I feel like the original code was still better.

  • Yes and it is the case - my next idea is:

    function planChime() {
      chimeTimer = setTimeout(function() {
        Bangle.buzz().then(() => {
          setTimeout(()=>{
        clearTimeout(chimeTimer);
       chimeTimer = undefined;
             planChime();
          }, 2000);
          });
      }, 3600000 - (Date.now() % 3600000));
    }
    
About

Avatar for Gordon @Gordon started