Fix: Prevent function from spamming API after sleep#93
Fix: Prevent function from spamming API after sleep#93sumanjeet0012 wants to merge 2 commits intodrand:masterfrom
Conversation
- Adjusted the function to calculate the next round by time when the computer wakes from sleep, preventing unnecessary API calls.
| const targetRound = roundAt(now, info) | ||
|
|
||
| const nextRoundTime = roundTime(info, targetRound) | ||
| const waitTime = nextRoundTime - now |
There was a problem hiding this comment.
will waitTime ever be > 0 here given we're checking the round at now?
There was a problem hiding this comment.
Yes, I think the difference between nextRoundTime (the time of the next round, which will occur in the future) and the current time will be greater than 0.
Is there anything incorrect here?
There was a problem hiding this comment.
assuming 3 second rounds:
If we start at time 0 and it's currently time 1, roundAt(now, info) returns 1 (which started at time 0), therefore we will wait 0 seconds.
On the next iteration, it will still be time 1(ish), and roundAt(now, info) will still return 1, waiting 0 seconds again
I'd have assumed you need to increment the round to get the next round
There was a problem hiding this comment.
indeed it seems the tests are failing for the same reason
Description
Fixes #88 .
This PR addresses issue #88, where the
watchfunction was found to spam the API after a computer resumes from sleep.Changes Made
watchfunction to calculate the next round based on the current time when the computer wakes up, thus preventing unnecessary API calls during the transition.