-
Notifications
You must be signed in to change notification settings - Fork 22.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add scheduler.yield() #35960
Add scheduler.yield() #35960
Conversation
Preview URLs
External URLs (1)URL:
(comment last updated: 2024-09-25 15:57:35) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM.
Have a few (non-blocking) comments where it could potentially be improved further.
|
||
By default, `scheduler.yield()` is run with a [`'user-visible'`](/en-US/docs/Web/API/Prioritized_Task_Scheduling_API#user-visible) priority. However, the continuation from a `scheduler.yield()` has a slightly different behavior than `scheduler.postTask()` tasks of the same `priority`. | ||
|
||
`scheduler.yield()` enqueues its task at the front of a priority level's queue, while `scheduler.postTask()` tasks go at the end (in the spec, this is defined by a task queue's [effective priority](https://wicg.github.io/scheduling-apis/#scheduler-task-queue-effective-priority)). This means that with the same priority, the `scheduler.yield()` continuation will come first, allowing additional flexibility in how tasks can be scheduled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whhhattt! This is news to me!
Even more reason to use yield
over postTask
then!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this generally looks fine, but I added a couple of suggestions for prose.
|
||
### Basic usage | ||
|
||
Long tasks can be broken up by awaiting `scheduler.yield()`. The function returns a promise, yielding the {{Glossary('main thread')}} to allow the browser to execute other pending work—like responding to user input—if needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this glossary definition should be linked much earlier in the guide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha good call. I think it might have migrated down as the article evolved :) Moved to first instance of "main thread".
Co-authored-by: Jeremy Wagner <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also clarified the priority inheritance to be the best kind of correct, and added mention of requestIdleCallback priority inheritance
|
||
### Basic usage | ||
|
||
Long tasks can be broken up by awaiting `scheduler.yield()`. The function returns a promise, yielding the {{Glossary('main thread')}} to allow the browser to execute other pending work—like responding to user input—if needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha good call. I think it might have migrated down as the article evolved :) Moved to first instance of "main thread".
|
||
### Inheriting task priorities | ||
|
||
A `scheduler.yield()` within a `scheduler.postTask()` task will inherit the task's priority. For example, work after a `scheduler.yield()` within a [`'background'`](/en-US/docs/Web/API/Prioritized_Task_Scheduling_API#user-blocking) low-priority task will also be scheduled as `'background'` by default (but, again, inserted in the boosted `'background'` priority queue, so running before any `'background'` `postTask` tasks). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with the MDN style guide, but I noticed that you have single quotes around the string 'background' here but then use double quotes in the code snippet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn you prettier. Switching to double quotes for everything 🤮
@chrisdavidmills I think this is ready for you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brendankenny nice work! I've reviewed this pretty thoroughly and left quite a few comments, but most of them are fairly minor language suggestions/nitpicks.
Co-authored-by: Chris Mills <[email protected]> Co-authored-by: Joshua Chen <[email protected]>
Co-authored-by: Chris Mills <[email protected]>
Thanks for the great review @chrisdavidmills! I believe everything should be addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @brendankenny. Let's get this published, and we can iterate further if needed.
* Add scheduler.yield() * Apply suggestions from code review Co-authored-by: Jeremy Wagner <[email protected]> * review feedback * clarify priority queues and requestIdleCallback * fix one more reference to front of the queue behavior * more review feedback * Apply suggestions from code review Co-authored-by: Chris Mills <[email protected]> Co-authored-by: Joshua Chen <[email protected]> * Apply suggestions from code review Co-authored-by: Chris Mills <[email protected]> * heading changes * syntax consistency in headings --------- Co-authored-by: Jeremy Wagner <[email protected]> Co-authored-by: Chris Mills <[email protected]> Co-authored-by: Joshua Chen <[email protected]>
* Add scheduler.yield() * Apply suggestions from code review Co-authored-by: Jeremy Wagner <[email protected]> * review feedback * clarify priority queues and requestIdleCallback * fix one more reference to front of the queue behavior * more review feedback * Apply suggestions from code review Co-authored-by: Chris Mills <[email protected]> Co-authored-by: Joshua Chen <[email protected]> * Apply suggestions from code review Co-authored-by: Chris Mills <[email protected]> * heading changes * syntax consistency in headings --------- Co-authored-by: Jeremy Wagner <[email protected]> Co-authored-by: Chris Mills <[email protected]> Co-authored-by: Joshua Chen <[email protected]>
Description
Chrome 129 adds
yield
method to the Scheduler interface. This PR adds reference documentation for the new method.Additional details