-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Editorial: rigorize tasks and task queuing #4465
Conversation
This introduces tasks as a proper struct, with well-defined fields, and makes "queue a task" and "queue a microtask" into more well-defined algorithms for setting up and queuing those tasks. It centralizes and calls out the still-somewhat-vague parts in the "implied event loop" and "implied document" definitions. Other minor cleanups and clarifications: * Fixes "performing a microtask checkpoint" to be a boolean; previously it was referred to as a flag but set to true or false. * Fixes #4242 by making it clearer how tasks are chosen by the event loop. * Adds more guidance text around how task sources and task queues interact. * Introduces a new subsection "Queuing tasks" to contain the task-queuing definitions, which were previously spread out through "Definitions" (for non-microtask tasks) and "Processing model" (for microtasks). * Centralizes all properties of the event loop into "Definitions". They were previously spread out throughout "Definitions" and "Processing model".
<dd>A <code>Document</code> associated with the task, or null for tasks that are not in a | ||
<span>window event loop</span>.</dd> | ||
|
||
<dt>A <dfn data-export="">script evaluation environment settings object set</dfn></dt> |
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.
Why is only this field exported?
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.
This one is referenced from the long tasks spec. None of the others were exported at this time, and probably should not be.
|
||
<p>To <dfn data-export="">queue a task</dfn> on a <span>task source</span> <var>source</var>, | ||
which performs a series of steps <var>steps</var>, optionally given an event loop <var>event | ||
loop</var>:</p> |
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.
This requires rephrasing almost all callers, right?
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.
To introduce a "on the X task source"? Yes, that's the intent, is to require being explicit there. Or did you mean something else?
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.
Well, that this PR doesn't change any callers.
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 thought we could do that as a follow-up, to avoid this growing into a mega-patch. Do you think it's necessary to do that in the same patch?
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.
Not necessarily, if it'll happen.
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.
Filed #4506 to track. Do you think it's worth linking to in the meantime, from the spec?
below.</p></li> | ||
on one of the <span>event loop</span>'s <span data-x="task queue">task queues</span>. In the case | ||
of a <span>window event loop</span>, the task selected must have a <span | ||
data-x="concept-task-document">document</span> that is <span>fully active</span>. The user agent |
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 don't think this has quite the same meaning as the old text. This is a requirement on the selected task, whereas before it was a requirement on how to select.
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.
What would the new text allow/disallow that the old text did not?
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.
The new text is unclear to me. I select the oldest task. It violates the must, now what?
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.
You're not allowed to do things that violate the must, so you don't do that.
Can you suggest alternate phrasing that fixes the concerns in #4242? This was my best attempt.
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.
Maybe we can make it an algorithm instead?
Let oldest task be the oldest task.
While true:
- If oldest task's document is null or is fully active, then break.
- Set oldest task to the task following oldest task.
- Task queues are sets, not lists, and not queues. Explains why. - Microtask queue can be a queue. - Explain that not just source, but also document and script evaluation environment settings object set, are irrelevant in most cases for microtask. - Fix oldestTask selection algorithm to be more precise, by introducing a "runnable" task concept. - Use more Infra
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.
This looks pretty great to me. Perhaps we should find one additional reviewer though given the complexity of the algorithm. Alternatively I could give it a fresh look next week to see if it still makes sense.
<dl> | ||
<p class="note"><span data-x="task queue">Task queues</span> are <span data-x="set">sets</span>, | ||
not <span data-x="queue">queues</span>, because <a href="#step1">step one of the event loop | ||
processing model</a> grabs the first <span data-x="concept-task-runnable"><em>runnable</em></span> |
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.
s/grabs/removes/?
event loop</span>. This is the only case in which the <span | ||
data-x="concept-task-source">source</span>, <span data-x="concept-task-document">document</span>, | ||
and <span>script evaluation environment settings object set</span> of the microtask are consulted; | ||
they are ignored by the <span>perform a microtask checkpoint</span> algorithm.</p> |
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.
Interesting! This is news to me. I thought we processed the microtask queue after looking for an item in the task queues (whether a task is found or not).
<li><p>If <var>event loop</var> is not a <span>window event loop</span>, then return | ||
null.</p></li> | ||
|
||
<li><p>If the task is being queued in the context of an element, then return the element's |
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.
What does "in the context of an element" mean? Does it mean it looks inside the task to see what the algorithm acts upon?
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.
It's pretty fuzzy, to be honest. This is just porting the preexisting vague language.
queue</span>. If there is no task to select, then jump to the <i>microtasks</i> step | ||
below.</p></li> | ||
<li id="step1"><p>Let <var>taskQueue</var> be one of the <span>event loop</span>'s <span | ||
data-x="task queue">task queues</span>, chosen in a user-agent-defined manner, with the |
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.
Could it end up picking the microtask task queue at this point?
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.
The "microtask queue" is not a "task queue"; all "task queues" are implementation-defined. I will add a note making that explicit.
If @annevk or @jakearchibald wants to take another look at my latest commit, I'd love to commit this :). |
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 still happy with this.
This introduces tasks as a proper struct, with well-defined fields, and
makes "queue a task" and "queue a microtask" into more well-defined
algorithms for setting up and queuing those tasks. It centralizes and
calls out the still-somewhat-vague parts in the "implied event loop" and
"implied document" definitions.
Other minor cleanups and clarifications:
it was referred to as a flag but set to true or false.
loop.
interact.
task-queuing definitions, which were previously spread out through
"Definitions" (for non-microtask tasks) and "Processing model" (for
microtasks).
were previously spread out throughout "Definitions" and "Processing
model".
/cc @littledan, although this is probably only tangentially related to stuff you've been thinking about.
Interesting things to note about the task struct is how rarely some of its fields are used:
/index.html ( diff )
/webappapis.html ( diff )