-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay53Promiseerrorandapi.html
62 lines (53 loc) · 1.87 KB
/
Day53Promiseerrorandapi.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 lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Day53</title>
</head>
<body>
<script>
// Gobal error handling
window.addEventListener('unhandledrejection',function(event){ // if anything unhandled this will be triggered
console.log(event.promise);
console.log(event.reason);
})
new Promise(()=>{
throw new Error("this is unhandled error mr/mrs developer");
})
//Promise.all
Promise.all([
new Promise((resolve)=>{ resolve('ponmani')}),
new Promise((resolve)=>{ resolve('venkatesan')}),
new Promise((resolve)=>{ resolve('vellore')})
]).then((result)=>{
console.log(result);// array as a result [ponmani,venkatesan,vellore]
})
//Promise.race
Promise.race([
new Promise((resolve)=>{setTimeout(()=>resolve('ponmani'),2000)}),
new Promise((resolve)=>{ resolve('venkatesan')}),
new Promise((resolve)=>{ resolve('vellore')})
]).then((result)=>{
console.log(result);// venkatesan
})
//promise.settled
Promise.allSettled([
new Promise((resolve)=>{setTimeout(()=>resolve('ponmani'),2000)}),
new Promise((reject)=>{ reject(new Error('whoops!'))}),
new Promise((resolve)=>{ resolve('vellore')})
]).then((result)=>{
console.log(result);// venkatesan
})
// Asyn and await
(async function waiting(){
let name =new Promise((resolve,reject)=>{
setTimeout (()=>resolve('ponmani'),2000);
})
let myname=await name;
console.log(myname);
console.log('end');
})()
</script>
</body>
</html>