Skip to content

Fix: Prevent function from spamming API after sleep #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sumanjeet0012
Copy link
Contributor

Description

Fixes #88 .

This PR addresses issue #88, where the watch function was found to spam the API after a computer resumes from sleep.

Changes Made

  • Modified the watch function to calculate the next round based on the current time when the computer wakes up, thus preventing unnecessary API calls during the transition.

- Adjusted the  function to calculate the next round by time when the computer wakes from sleep, preventing unnecessary API calls.
CluEleSsUK
CluEleSsUK previously approved these changes Feb 19, 2025
const targetRound = roundAt(now, info)

const nextRoundTime = roundTime(info, targetRound)
const waitTime = nextRoundTime - now
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will waitTime ever be > 0 here given we're checking the round at now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed it seems the tests are failing for the same reason

@CluEleSsUK CluEleSsUK dismissed their stale review February 19, 2025 10:09

saw a potential issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

watch spams API after sleep
2 participants