BackgroundTimer.setInterval is not synchronized with the actual timer
See original GitHub issueBackgroundTimer.setInterval()
is running 4-5 seconds
more than the actual timer.
when I try to run this for 5 minutes
it’s actually running for 5 minutes 5 seconds
. which is not good
x = BackgroundTimer.setInterval(() => {
let { eventDate } = state;
if (eventDate <= 0) {
clearInterval(x);
}
else {
eventDate = eventDate.subtract(1, 's');
// const hours = eventDate.hours();
// const mins = eventDate.minutes();
// const secs = eventDate.seconds();
setState({
// hours,
eventDate
});
}
}, 1000);
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7
Top Results From Across the Web
the time is not correct · Issue #250 · ocetnik/react-native ...
Same issue I'm facing. Background.setInterval is not synchronized with the actual time. it running 4-5 seconds more than the actual time ...
Read more >react-native-background-timer - Bountysource
BackgroundTimer.setInterval() is running 4-5 seconds more than the actual timer. when I try to run this for 5 minutes it's actually running for...
Read more >Make JavaScript interval synchronize with actual time
The basic idea is not to use setInterval() , but rather to calculate each time how many milliseconds later you want the loop...
Read more >722410 - setInterval stops when window goes out of focus
We have decent coverage for setTimeout, but not setInterval. - --disable-background-timer-throttling seems broken at the moment.
Read more >Why Javascript timer is unreliable, and how can you fix it
Remember when I said Javascript is single threaded, well… that's true, but not strictly. Say when you run a block of code inside...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Maybe this can help you: https://aloukissas.medium.com/how-to-build-a-background-timer-in-expo-react-native-without-ejecting-ea7d67478408 You can update the eventDate in the function by substracting the difference between the start date and
now
.This is how I used it in my timer:
@jnjacobson thanks! That really helped!