-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync.html
62 lines (43 loc) · 1.46 KB
/
async.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html>
<head>
<!-- Load babel 5 - babel-core
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.38/browser.js"></script> -->
<script>
const delay = seconds => {
return new Promise(
resolve => setTimeout(resolve, seconds * 1000)
)
};
const countToFive = async() => {
console.log('zero seconds');
await delay(1);
console.log('1 second');
await delay(2);
console.log('2 second');
await delay(5);
console.log('5 second');
};
countToFive();
</script>
<title>Async</title>
</head>
<body>
<h1>Hit the pit</h1>
<h2>Async</h2>
<ul>
<li>async()</li>
<li>await</li>
</ul>
<h3>Error: </h3>
<code>regeneratorRuntime is not defined</code>
<h3>Solution: </h3>
<p>Remove babel script because babel version is not working with async function.</p>
<h3>If we remove async and await, it just output all texts</h3>
<h3>Benefits of Async function: </h3>
<ul>
<li>Write some cleaner more readable code and take advantage of async behaviour</li>
<li>We have error handling and easier to debug</li>
</ul>
</body>
</html>