Boot, alarm app and clearInterval

Posted on
  • I've been studying the alarm app and can not figure out how alarm.js can safely call clearInterval without affecting everything else that may be using timers or intervals. Is there something about the bangle architecture I'm missing that limits the impact of clearInterval?

  • Looks like alarm.js is only called from boot.js which is run at boot time. What else you think would be running at that time?

    EDIT: Just ignore this, I didn't realize there is potentially long setTimeout in boot.js - so yes good question.

  • Would an immediate run not still pose problems for something earlier in the boot process?

  • Hi,

    As noted, I think alarm.js is only called when an alarm is due, and it is called with load(...) so everything else is removed at that point and it's just the boot.js code that is run.

    Reasoning for it is in the comments above it:

    // Chances are boot0.js got run already and scheduled *another*
    // 'load(alarm.js)' - so let's remove it first!
    clearInterval();
    

    I'm not sure it's really a huge issue as it would only ever affect things in the case the alarm actually goes off. Are you actually having issues and you think that might be the cause?

    I guess now we have __FILE__ defined, boot.js could check that instead and just not schedule an alarm if global.__FILE__=="alarm.js"

  • Are you actually having issues and you think that might be the cause?

    Not that I'm aware of. I intend to make timer app that can run in the background so I was trying to understand understand what exactly the alarm app does and why it does.

    As noted, I think alarm.js is only called when an alarm is due, and it is called with load(...) so everything else is removed at that point and it's just the boot.js code that is run.

    Does that mean that the clearInterval effectively only applies until alarm.js is done? That certainly would make it very unlikely to impact pending timeouts... I may have been more confused about how often boot actually runs in that case.

    Is there some distinction between boot.js and boot0.js that could lead to another load of alarm.js? Or is there some some special handling of all alarm.js files as hinted in the BangleApps Readme (although I couldn't really find any more on that) that may affect it?

    I may be overthinking things...

  • I intend to make timer app that can run in the background

    Is there any chance you could just use/update the existing alarm app - since that handles timers too? You could then just make your app update alarm.json with the timers it wants scheduled.

    Does that mean that the clearInterval effectively only applies until alarm.js is done?

    Yes, that's right - because alarm.js either uses load to load another app straight away, or is displays a fullscreen message.

    another load of alarm.js?

    No, I don't think so... Once load(...) is called it's like a complete restart - it gets rid of everything and starts from scratch

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Boot, alarm app and clearInterval

Posted by Avatar for Subtlewolf @Subtlewolf

Actions