Giter Site home page Giter Site logo

Comments (3)

SalomonBrys avatar SalomonBrys commented on July 20, 2024

I think you misunderstood _tick = (_tick + 1) % 10).
It means that _tick will be incremented by _one_ and then set to the result modulo ten.

So, before _uiHandler.post(_ticker), we know that _tick == lastTick, then the _ticker task will increment _tick by one and ensure that it remains within [0-10[.

  • When lastTick is 0, then _ticker will (try to) set _tick to 1.
  • When lastTick is 1, then _ticker will (try to) set _tick to 2.
  • ...
  • When lastTick is 9, then _ticker will (try to) set _tick to 0.

So, as the _ticker task is only run once between lastTick = _tick and if (_tick == lastTick), _tick can not be the same as lastTick after one _ticker execution.

The modulo 10 is because, you know, we have 10 fingers. Any modulo would have done. In truth, the actual best meaningful modulo would have been (Integer.MAX_VALUE - 1).

I did this to avoid overflow.
Granted, to overflow, with _timeoutInterval set to 5 seconds, the app would have to remain opened 340 years...

...I hope future generation will remember me fondly ;)

from anr-watchdog.

PanWangJ avatar PanWangJ commented on July 20, 2024

Ah, the problem of me is not with the _tick = (_tick + 1) % 10, but actually what I got wrong is with the Runnable object _ticker. I thought that this Runnable object will keep running(not just once but a lot of times) in the main thread and thus change the value of _tick from 0 to 9 continuously. Anyway, thanks for your explanation, I believe this is a stupid mistake that I will bear in mind for quite a long time.
Thanks again!

from anr-watchdog.

PanWangJ avatar PanWangJ commented on July 20, 2024

And, you are really funny about the 340 years thing :)

from anr-watchdog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.