-
Notifications
You must be signed in to change notification settings - Fork 0
/
testgooglechart_delay.html
60 lines (43 loc) · 1.21 KB
/
testgooglechart_delay.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
<!DOCTYPE html>
<html>
<body>
<p>Click the button to fetch a value within 3 seconds, then display it.</p>
<p id="message">Message</p>
<button onclick="getAndDisplayRemoteValues()">Try it</button>
<script>
// With a setTimeOut
// var myVar,occur;
// function getAndDisplayRemoteValues() {
// myVar = setTimeout(
// ()=>{occur = "12";
// document.getElementById("message").innerHTML = occur;
// },3000);
// }
// With a setTimeOut and a callback
// function getAndDisplayRemoteValues(){
// // occur is a single value fetched from the server
// var occur;
// setTimeout(function(){ occur = 12; myFunction(occur)}, 3000);
// function myFunction(value){
// document.getElementById("message").innerHTML = value;
// }
// }
// // With a Promise
function getAndDisplayRemoteValues(){
var occur;
let myPromise = new Promise(
(resolve)=>{
setTimeout(()=>{ // "Simulate a request to the server and waiting 3 sec to receive it"
resolve(occur = 12);
}, 3000); // when successful
});
// "Consuming Code" (Must wait for a fulfilled Promise)
myPromise.then(
(value) => { /* print the graph if successful */
document.getElementById("message").innerHTML = value;
}
);
}
</script>
</body>
</html>