-
Notifications
You must be signed in to change notification settings - Fork 0
/
Promise.html
49 lines (39 loc) · 1018 Bytes
/
Promise.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
<script>
/* let complete = true;
let prom0 = new Promise(function(resolve,reject){
if(complete){
resolve("Completed!")
}
else{
reject("Incomplete!")
}
})
console.log(prom0)
*/
function prom(complete) {
return new Promise(function (resolve, reject) {
console.log("Fetching data, please wait")
setTimeout(()=>{
if (complete) {
resolve("I am successful")
}
else {
reject("I didn't attempt")
}
}, 2000)
});
}
// let onfulfilment = (result) => {
// console.log(result)
// }
// let onrejection = (error) => {
// console.log(error)
// }
// prom(false).then(onfulfilment);
// prom(false).catch(onrejection);
prom(false).then((result) => {
console.log(result)
}).catch((error) => {
console.log(error)
});
</script>