Skip to content

async yield function #3476

Closed Answered by daxpedda
emilk asked this question in Q&A
Discussion options

You must be logged in to vote

I actually found two viable solutions for this in the meantime:

  1. window.requestIdleCallback() which can be used to do exactly what you want here. Just let the future sleep and wake it up in the callback. Though this is unsupported in Safari (Bugzilla).

  2. While looking for Safari polyfills, I found that using setTimeout() with a delay of 0 can also do the job:

    If this parameter is omitted, a value of 0 is used, meaning execute "immediately", or more accurately, the next event cycle.

    Unfortunately nested timeouts will prevent this behavior and instead delay it by 4ms.

Replies: 8 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by daxpedda
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants
Converted from issue

This discussion was converted from issue #3359 on June 09, 2023 22:57.