Skip to content
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

setInterval function fires WAY too often #4

Closed
simonw opened this issue Nov 30, 2022 · 1 comment
Closed

setInterval function fires WAY too often #4

simonw opened this issue Nov 30, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@simonw
Copy link
Owner

simonw commented Nov 30, 2022

Just noticed this:

// Every 1s, update the time remaining
let interval = setInterval(() => {
const now = new Date();
const secondsRemaining = (ephemeralExpiresAt - now) / 1000;
if (secondsRemaining <= 0) {
clearInterval(interval);
timeRemainingDiv.innerText = 'This table has expired';
} else {
const timeRemaining = ephemeralFormatSecondsAsMinutesAndSeconds(secondsRemaining);
timeRemainingDiv.innerText = `This table expires in ${timeRemaining}`;
}
});

I didn't pass the time argument, so it runs thousands of times a second.

@simonw simonw added the bug Something isn't working label Nov 30, 2022
@simonw
Copy link
Owner Author

simonw commented Nov 30, 2022

I'm going to set it to run ever 800ms.

If I run every 1000ms there's always a chance that the timer might jump down two seconds instead of one if I get unlucky with the exact intervals.

@simonw simonw closed this as completed in da4120b Nov 30, 2022
simonw added a commit that referenced this issue Nov 30, 2022
simonw added a commit to simonw/datasette that referenced this issue Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant