Skip to content

Commit e6c47f5

Browse files
authored
Add specification for scheduler.yield() method (#88)
1 parent a3b0d5c commit e6c47f5

File tree

4 files changed

+282
-62
lines changed

4 files changed

+282
-62
lines changed

spec/controlling-tasks.md

+9
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ object |signal|, [=set/append=] |algorithm| to |signal|'s [=TaskSignal/priority
194194
1. Set |signal|'s [=TaskSignal/priority changing=] to false.
195195
</div>
196196

197+
<div algorithm>
198+
To <dfn>create a fixed priority unabortable task signal</dfn> given {{TaskPriority}} |priority|
199+
and a [=ECMAScript/realm=] |realm|.
200+
201+
1. Let |init| be a new {{TaskSignalAnyInit}}.
202+
1. Set |init|["{{TaskSignalAnyInit/priority}}"] to |priority|.
203+
1. Return the result of [=creating a dependent task signal=] from « », |init|, and |realm|.
204+
</div>
205+
197206
### Garbage Collection ### {#sec-task-signal-garbage-collection}
198207

199208
A [=TaskSignal/dependent=] {{TaskSignal}} object must not be garbage collected while its

spec/introduction.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,16 @@ some use cases, but this only applies to idle tasks and does not account for
5353
tasks whose priority can change, e.g. re-prioritizing off-screen content in
5454
response to user input, like scrolling.
5555

56-
This document introduces a new interface for developers to schedule and control
57-
prioritized tasks. The {{Scheduler}} interface exposes a
58-
{{Scheduler/postTask()}} method to schedule tasks, and the specification
59-
defines a number of {{TaskPriority|TaskPriorities}} that control execution
60-
order. Additionally, a {{TaskController}} and its associated {{TaskSignal}}
61-
can be used to abort scheduled tasks and control their priorities.
56+
This specification introduces a new interface for developers to schedule and
57+
control prioritized tasks and continuations. A task in this context is a
58+
JavaScript callback that runs asynchronously in its own [=event loop=] [=task=].
59+
A continuation is the resumption of JavaScript code in a new [=event loop=]
60+
[=task=] after yielding control to the browser. The {{Scheduler}} interface
61+
exposes a {{Scheduler/postTask()}} method to schedule tasks and a
62+
{{Scheduler/yield()}} method to schedule continuations. The specification
63+
defines a number of {{TaskPriority|TaskPriorities}} to control task and
64+
continuation execution order. Additionally, a {{TaskController}} and its
65+
associated {{TaskSignal}} can be used to abort scheduled tasks and control their
66+
priorities.
6267

6368
</div>

spec/patches.md

+48
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ determine task execution order across [=scheduler task queues=] of the same {{Ta
3232
all {{Scheduler}}s associated with the same [=event loop=]. A timestamp would also suffice as long
3333
as it is guaranteed to be strictly increasing and unique.
3434

35+
Add: An [=event loop=] has a <dfn for="event loop">current scheduling state</dfn> (a [=scheduling
36+
state=] or null), which is initialized to null.
37+
3538
### <a href="https://html.spec.whatwg.org/multipage/webappapis.html#event-loop-processing-model">Event loop: processing model</a> ### {#sec-patches-html-event-loop-processing}
3639

3740
Add the following steps to the event loop processing steps, before step 2:
@@ -56,3 +59,48 @@ Issue: The |taskQueue| in this step will either be a [=set=] of [=tasks=] or a [
5659
[=scheduler tasks=]. The steps that follow only [=set/remove=] an [=set/item=], so they are
5760
*roughly* compatible. Ideally, there would be a common task queue interface that supports a `pop()`
5861
method that would return a plain [=task=], but that would involve a fair amount of refactoring.
62+
63+
### <a href="https://html.spec.whatwg.org/multipage/webappapis.html#hostmakejobcallback">HostMakeJobCallback(callable)</a> ### {#sec-patches-html-hostmakejobcallback}
64+
65+
Add the following before step 5:
66+
67+
1. Let |event loop| be <var ignore=''>incumbent settings<var>'s
68+
[=environment settings object/realm=]'s [=realm/agent=]'s [=agent/event loop=].
69+
1. Let |state| be |event loop|'s [=event loop/current scheduling state=].
70+
71+
Modify step 5 to read:
72+
73+
1. Return the <span>JobCallback Record</span> { \[[Callback]]: <var ignore=''>callable</var>,
74+
\[[HostDefined]]: { \[[IncumbentSettings]]: <var ignore=''>incumbent settings</var>,
75+
\[[ActiveScriptContext]]: <var ignore=''>script execution context</var>,
76+
\[[SchedulingState]]: |state| } }.
77+
78+
### <a href="https://html.spec.whatwg.org/multipage/webappapis.html#hostcalljobcallback">HostCallJobCallback(callback, V, argumentsList)</a> ### {#sec-patches-html-hostcalljobcallback}
79+
80+
Add the following steps before step 5:
81+
82+
1. Let |event loop| be <var ignore=''>incumbent settings<var>'s
83+
[=environment settings object/realm=]'s [=realm/agent=]'s [=agent/event loop=].
84+
1. Set |event loop|'s [=event loop/current scheduling state=] to
85+
<var ignore=''>callback</var>.\[[HostDefined]].\[[SchedulingState]].
86+
87+
Add the following after step 7:
88+
89+
1. Set |event loop|'s [=event loop/current scheduling state=] to null.
90+
91+
## <a href="https://w3c.github.io/requestidlecallback/">`requestIdleCallback()`</a> ## {#sec-patches-requestidlecallback}
92+
93+
### <a href="https://w3c.github.io/requestidlecallback/#invoke-idle-callbacks-algorithm">Invoke idle callbacks algorithm</a> ### {#sec-patches-invoke-idle-callbacks}
94+
95+
Add the following step before step 3.3:
96+
97+
1. Let |realm| be the [=relevant realm=] for <var ignore=''>window</var>.
98+
1. Let |state| be a new [=scheduling state=].
99+
1. Set |state|'s [=scheduling state/priority source=] to the result of [=creating a fixed priority
100+
unabortable task signal=] given "{{TaskPriority/background}}" and |realm|.
101+
1. Let |event loop| be |realm|'s [=realm/agent=]'s [=agent/event loop=].
102+
1. Set |event loop|'s [=event loop/current scheduling state=] to |state|.
103+
104+
Add the following after step 3.3:
105+
106+
1. Set |event loop|'s [=event loop/current scheduling state=] to null.

0 commit comments

Comments
 (0)