-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample2.html
43 lines (38 loc) · 955 Bytes
/
example2.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>example2</title>
<script src="../dist/es5/task-queue-min.js"></script>
</head>
<body id="app">
<script>
var taskQueue = new TaskQueue();
var aw = taskQueue.await;
var bodyEl = document.getElementById('app');
if (bodyEl) {
var resData = [];
// 异步API
aw(function (next) {
bodyEl.innerText = '数据加载中...';
setTimeout(function () {
resData = [{name: 'Test1'}, {name: 'Test2'}, {name: 'Test3'}];
next();
}, 3000);
});
// 结果处理
aw(function () {
bodyEl.innerText = '';
resData.forEach(function (item) {
var divEl = document.createElement('div');
divEl.innerText = '姓名:' + item.name;
bodyEl.append(divEl);
});
});
aw(function () {
taskQueue.close();
});
}
</script>
</body>
</html>