You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • I think that's pretty broken too... If you run it twice you get two timeouts. Can you try adding some prints to the original code to see what's going on?

    We use that pattern (if (x) clearTimeout(x);x = setTimeout(function() { x=undefined; ... },...)) all over the place so I don't think there's anything specifically wrong with it.

    function planChime() {
      if (chimeTimer) {
        clearTimeout(chimeTimer);
      }
      chimeTimer = setTimeout(function() {
        chimeTimer = undefined;
        Bangle.buzz().then(() => {
          setTimeout(function(){
             planChime();
          }, 2000);
          });
      }, 3600000 - (Date.now() % 3600000));
    }
    
  • I'm still struggeling on this.
    Edit: Post deleted - I had another idea, still testing ..

  • Sorry Gordon that I have to come back with this.

    if (x) clearTimeout(x);x = setTimeout(function() { x=undefined; ... },...)
    

    This pattern leaves dangeling handles not only in theory, but also on the watch. clearTimeout is never called. If you have no timeout, then you create one. When the function is executed on time, you delete first your handle to this timer. But when the handle is lost the timeout never gets cleared, because there is no handle to it.

    Just a note of removing chimeTimer=undefined - chimeTimer will still be set to the ID
    of the timer that has now finished,

    Shouldn't this be done by clearTimeout? I feel that the problem is here.

    I tried multiple alternative solutions for this. All end up in a sudden infinite buzzing after 10-15 hours and FIFO_FULL. The FIFO_FULL also appears with the Anton clock, which also uses this pattern. I'm a JS developer, but I'm really struggeling to develop a pattern which does work. Any logical correct solutions to the timer problem do not work. If you use apps this will never become visible, because everything is reset with app change.

    The strange thing is: All was fine also on v1 until approx a year ago. Did you change the behaviour of timers in the past?

    What should work should look like this:

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

    or at least

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

    But it does not.

About

Avatar for Gordon @Gordon started