#how to have a reactive current time?

22 messages ยท Page 1 of 1 (latest)

nocturne pier
#

there's no efficient way to have something like that

#

In what scenario would you need something like that? It feels to me like the wrong solution to the right problem potentially

#

Do you need sub-second resolution?

#

I don't think I've heard of it ๐Ÿค”

#

Is that caused by setInterval's scheduling slipping over time?

#

Is it caused by the main thread blocking for long enough that we can't update the countdown quickly enough? ๐Ÿค”

#

๐Ÿ‘

#

If setInterval is precise and the main thread is not blocked I'm not sure what else it could be though

craggy hazel
nocturne pier
#

But where is this jerky time issue originating from? ๐Ÿค”

#

a bit of an hack, but would updating your countdowns inside a requestAnimationFrame loop solve the problem?

#

๐Ÿค” problem solved ๐Ÿ˜‚ always good to take some measurements

#

I think setInterval is known to slip over time or something like that, I haven't looked into it myself, but there are packages on npm that supposedly give you a more robust interval, maybe that's the problem

#

Maybe on startup the main thread was blocked for too long

#

like I'm not sure another explanation is possible if this problem actually exists

#

Oh like you start the timer at 1500 milliseconds so you show the next second 500 milliseconds late?

#

I guess in that case one would need to do an initial setTimeout + a setInterval after that, or probably just scheduling a setTimeout for every second to be sure

#

it's probably worth addressing imo, because if the user spots that kind of thing it's a bit of a maddening issue for OCD people ๐Ÿคฃ

#

yeah 1 second is eternity

polar ice
#

Vue has a useTimestamp primitive that updates the current time using requestAnimationFrame. This is probably as close as you can get to the actual current time. https://vueuse.org/core/useTimestamp/

nocturne pier
#

depending on how crazy how wants to go with this one can get into nanoseconds-level precision

polar ice