forked from WICG/scheduling-apis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasksignal-propagation.html
More file actions
78 lines (63 loc) · 3.51 KB
/
tasksignal-propagation.html
File metadata and controls
78 lines (63 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<meta charset="utf-8">
<title>postTask Example: TaskSignal propagation</title>
<script src='support/common.js'></script>
<div id='content'></div>
<script>
async function runExample() {
function returnCurrentTaskSignal() {
return scheduler.currentTaskSignal;
}
async function propagationEqualityAndPriorities() {
var inherit_task_signal = await scheduler.postTask(returnCurrentTaskSignal,
{ signal: scheduler.currentTaskSignal });
appendToContent('div', "Passing currentTaskSignal should keep the same TaskSignal: " +
(inherit_task_signal == scheduler.currentTaskSignal).toString());
var inherit_priority_only = await scheduler.postTask(returnCurrentTaskSignal,
{ priority: scheduler.currentTaskSignal.priority });
appendToContent('div', "Passing priority only should not use the same TaskSignal: " +
(inherit_priority_only != scheduler.currentTaskSignal).toString());
appendToContent('div', "But it should have the same priority: " +
(inherit_priority_only.priority == scheduler.currentTaskSignal.priority).toString());
var inherit_task_signal_with_custom_priority = await scheduler.postTask(returnCurrentTaskSignal,
{ signal: scheduler.currentTaskSignal, priority: 'background' });
appendToContent('div', "Passing both signal and priority should not use the same TaskSignal: " +
(inherit_task_signal_with_custom_priority !== scheduler.currentTaskSignal).toString());
appendToContent('div', "And the priority parameter should be honored: " +
(inherit_task_signal_with_custom_priority.priority == 'background').toString());
var inherit_task_signal_through_fetch = await fetch('data:text/html,')
.then(() => scheduler.postTask(returnCurrentTaskSignal, { signal: scheduler.currentTaskSignal }));
appendToContent('div', "currentTaskSignal should be propagated even through a non-postTask promise like a fetch(): " +
(inherit_task_signal_through_fetch == scheduler.currentTaskSignal).toString());
}
function propagationAbort(controller) {
var inherit_task_signal = scheduler.postTask(() => {},
{ signal: scheduler.currentTaskSignal });
inherit_task_signal.then(() => {
console.log('This task should never run!');
})
.catch(() => {
appendToContent('div', "Passing currentTaskSignal reuses it, so abort() works.");
});
var inherit_priority_only = scheduler.postTask(() => {},
{ priority: scheduler.currentTaskSignal.priority });
inherit_priority_only.then(() => {
appendToContent('div', "Passing the currentTaskSignal's doesn't use the signal, so it doesn't get aborted.");
})
var inherit_task_signal_with_custom_priority = scheduler.postTask(() => {},
{ signal: scheduler.currentTaskSignal, priority: 'background' });
inherit_task_signal_with_custom_priority.then(() => {
console.log('This task should never run!');
})
.catch(() => {
appendToContent('div',
"Passing both the currentTaskSignal and a custom priority uses an implicit TaskSignal that follows currentTaskSignal, so abort() works.");
});
controller.abort();
}
let controller = new TaskController({priority: 'user-visible'});
await scheduler.postTask(propagationEqualityAndPriorities, { signal: controller.signal });
scheduler.postTask(() => propagationAbort(controller), { signal: controller.signal });
}
onload = runExample;
</script>