Skip to content

Commit 88cd2c8

Browse files
committed
Learn promise
1 parent 4f809cf commit 88cd2c8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

javascript/javascript/promise.html

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Promisify setTimeout</title>
6+
</head>
7+
<body>
8+
<h1>Did the promise finish?</h1>
9+
<div class="completion">Not yet</div>
10+
<script>
11+
function wait(ms) {
12+
return new Promise(function(resolve, reject) {
13+
window.setTimeout(function() {
14+
resolve();
15+
}, ms);
16+
});
17+
}
18+
19+
var milliseconds = 2000;
20+
wait(milliseconds).then(finish);
21+
22+
function finish() {
23+
var completion = document.querySelector(".completion");
24+
completion.innerHTML = "Complete after " + milliseconds + "ms.";
25+
}
26+
</script>
27+
</body>
28+
</html>

0 commit comments

Comments
 (0)