Skip to content

Commit 0e8de32

Browse files
committed
async in js
1 parent 09593f9 commit 0e8de32

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

Async/async.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<h1>JavaScript async / await</h1>
5+
<p id="demo"></p>
6+
7+
<script>
8+
function myDisplayer(some) {
9+
document.getElementById("demo").innerHTML = some;
10+
}
11+
12+
async function myFunction() {return "Hello";}
13+
14+
myFunction().then(
15+
function(value) {myDisplayer(value);},
16+
function(error) {myDisplayer(error);}
17+
);</script>
18+
19+
</body>
20+
</html>

Async/asynchronous.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
5+
<h1>JavaScript Functions</h1>
6+
<h2>Callback Functions</h2>
7+
8+
<p>The result of the calculation is:</p>
9+
<p id="demo"></p>
10+
11+
<script>
12+
function myDisplayer(something) {
13+
document.getElementById("demo").innerHTML = something;
14+
}
15+
16+
function myCalculator(num1, num2, myCallback) {
17+
let sum = num1 + num2;
18+
myCallback(sum);
19+
}
20+
21+
myCalculator(5, 5, myDisplayer);
22+
</script>
23+
24+
</body>
25+
</html>

Async/callbacks.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
5+
<h1>JavaScript Functions</h1>
6+
<h2>Function Sequence</h2>
7+
<p>JavaScript functions are executed in the sequence they are called.</p>
8+
9+
<p id="demo"></p>
10+
11+
<script>
12+
function myDisplayer(some) {
13+
document.getElementById("demo").innerHTML = some;
14+
}
15+
16+
function myFirst() {
17+
myDisplayer("Hello");
18+
}
19+
20+
function mySecond() {
21+
myDisplayer("Goodbye");
22+
}
23+
24+
myFirst();
25+
mySecond();
26+
</script>
27+
28+
</body>
29+
</html>
30+
31+

Async/promises.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
let myPromise = new Promise(function(myResolve, myReject) {
2+
// "Producing Code" (May take some time)
3+
4+
myResolve(); // when successful
5+
myReject(); // when error
6+
});
7+
8+
// "Consuming Code" (Must wait for a fulfilled Promise)
9+
myPromise.then(
10+
function(value) { /* code if successful */ },
11+
function(error) { /* code if some error */ }
12+
);
13+
14+
When the producing code obtains the result, it should call one of the two callbacks:
15+
16+
When Call
17+
Success myResolve(result value)
18+
Error myReject(error object)

javascript-docs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 09593f9ca9e396e383d1cdc49cf641ca9f0e9446

0 commit comments

Comments
 (0)