Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
thaliMobile's use of setInterval will kill our battery dead #697
Right now in thaliMobile there is a function called peerAvailabilityWatcher that runs on a regular interval (currently every second) and it checks to see if we have any really old peer availability announcements that need to be cleaned up. But this means that the device cannot ever really go to sleep as it will keep waking up every second! This is an awesome way to obliterate battery.
Thankfully the fix is pretty easy. We just need to calculate when the next entry is supposed to expire and set our timer for that long. Once we have no entries left then we don't set any timer at all. Once we get notified of a new peer event and enter it into peerAvailabilities then we set a new timer.