←back to thread

setBigTimeout

(evanhahn.com)
210 points cfj | 6 comments | | HN request time: 0.712s | source | bottom
1. darepublic ◴[] No.41881730[source]
instead of chaining together shorter timeouts, why not calculate the datetime of the delay and then invoke via window.requestAnimationFrame (by checking the current date ofc).
replies(3): >>41881800 #>>41881836 #>>41883972 #
2. ◴[] No.41881800[source]
3. augusto-moura ◴[] No.41881836[source]
Are you suggesting checking the date every frame vs scheduling long task every once in a long while? Can't tell if it is ironic or not, I'm sorry (damn Poe's law). But assuming not, it would be a lot more computationaly expensive to do that, timeouts are very optmized and they "give back" on the computer resources while in the meantime
replies(1): >>41882566 #
4. darepublic ◴[] No.41882566[source]
No irony intended I can be this dumb. Your point did occur to me as I posted, was just grasping at straws for a "clean" solution
5. jw1224 ◴[] No.41883972[source]
Unlike setTimeout, requestAnimationFrame callbacks are automatically skipped if the browser viewport is minimized or no longer visible. You wouldn’t want to miss the frame that matters!
replies(1): >>41885452 #
6. chii ◴[] No.41885452[source]
also, not to mention that setBigTimeout would still work in serverside js, while requestanimationframe doesn't!