Comment

Comment by ffsm8

JS is not a realtime language.

setTimeout() does not actually guarantee to run after the elapsed time. It merely gets queued for the next async execution window after that timer elapsed. Hence it can also be off by infinity and never get called - because JS is single threaded (unless you use a worker - which comes with its own challenges) and async windows only open if the main thread is "idle".

Usually, this is very close to the time you set via setTimeout, but it's very frequently slightly off, too.

parent ffsm8 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton