forked from WICG/scheduling-apis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscheduling-tasks.html
More file actions
34 lines (27 loc) · 1.16 KB
/
scheduling-tasks.html
File metadata and controls
34 lines (27 loc) · 1.16 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
<!DOCTYPE html>
<meta charset="utf-8">
<title>postTask Example: Scheduling Tasks</title>
<script src='support/common.js'></script>
<div id='content'></div>
<script>
async function runExample() {
// In the simplest case, postTask with no parameters will schedule a task at
// default priority, which is 'user-visible'.
let resultPromise = scheduler.postTask(() => {
appendToContent('h3', 'postTask Example: Scheduling Tasks');
});
// postTask returns a Promise, so the result can be awaited.
await resultPromise;
// |results| is an array of Promises representing postTask results.
let results = [];
// Valid priorities, from highest to lowest, are:
// 'user-blocking', 'user-visible', 'background'.
results.push(scheduler.postTask(() => 'This should be line 3', {priority: 'background'}));
results.push(scheduler.postTask(() => 'This should be line 2', {priority: 'user-visible'}));
results.push(scheduler.postTask(() => 'This should be line 1', {priority: 'user-blocking'}));
results.forEach((promise) => {
promise.then((result) => appendToContent('div', result));
});
}
onload = runExample;
</script>