Re:YouTube artificially slows down video load times when usi...
by shultays on Monday November 20, 2023 @09:17AM
(#38348524)
It is not literally a sleep though, isn't setTimeout more like a creating a delayed event? (I am not a webdev)
[ Parent
| on HN ]
Re:YouTube artificially slows down video load times when usi...
by Izkata on Monday November 20, 2023 @09:47AM
(#38349043)
You can't directly do a sleep in Javascript because it runs in the same thread as the UI - it would block the user from interacting with the page. This is effectively a sleep because after 5 seconds it's running the code in the passed-in function (not firing an event). The code in the function then resolves a promise, which runs other functions that can be specified later by what called the one using setTimeout.
Re:YouTube artificially slows down video load times when usi...
by yencabulator on Monday November 20, 2023 @09:50AM
(#38349070)
That's Javascript for you. Don't want to block the one thread from doing other things in the meanwhile.