this post was submitted on 08 Jul 2023
8 points (90.0% liked)

JavaScript

0 readers
1 users here now

founded 1 year ago
MODERATORS
 

Hi, I need to create a infinite (but breakable) cycle where I can slow down the cycle by awaiting promises inside. While cycle should be able to do this, but as you can see in the image, the duration is all over the place.

Why is this happening? Is there a way to make it close to the original sleep duration?

you are viewing a single comment's thread
view the rest of the comments
[โ€“] pe1uca@lemmy.pe1uca.dev 3 points 1 year ago* (last edited 1 year ago) (1 children)

Here's a talk at JSConf to help understand this

Jake Archibald on the web browser event loop, setTimeout, micro tasks, requestAnimationFrame, ...
https://youtu.be/cCOL7MC4Pl0

[โ€“] charolastra@programming.dev 2 points 1 year ago* (last edited 1 year ago)

This talk explains everything I had always wondered about concurrency in JS, but could never be bothered to read about.