←back to thread

setBigTimeout

(evanhahn.com)
210 points cfj | 1 comments | | HN request time: 0.202s | source
Show context
yifanl ◴[] No.41880869[source]
If we're pedantic, this doesn't actually do what's advertised, this would be waiting X timeouts worth of event cycles rather than just the one for a true Big timeout, assuming the precision matters when you're stalling a function for 40 days.
replies(3): >>41880887 #>>41882515 #>>41890330 #
keithwhor ◴[] No.41880887[source]
I haven’t looked at the code but it’s fairly likely the author considered this? eg the new timeout is set based on the delta of Date.now() instead of just subtracting the time from the previous timeout.
replies(2): >>41880912 #>>41882760 #
gnachman ◴[] No.41882760[source]
That wouldn't very well because Date.now() isn't monotonic.
replies(1): >>41886457 #
1. _flux ◴[] No.41886457[source]
There is a monotonic time source available in JavaScript, though: https://developer.mozilla.org/en-US/docs/Web/API/Performance...

As I understand it, the precision of such timers has been limited a bit in browsers to mitigate some Spectre attacks (and maybe others), but I imagine it would still be fine for this purpose.