-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjune14.js
94 lines (72 loc) · 1.84 KB
/
june14.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//Async & await
let task = new Promise((resolve,reject) => {
let pass = true
if (pass) {
resolve("You have Passed first test")
} else {
reject("Sorry , better luck next time")
}
})
let tech = new Promise((resolve,reject) =>{
let pass = true
if (pass) {
resolve("You have Passed second test")
} else {
reject("Sorry , better luck next time")
}
} )
let manager = new Promise((resolve,reject) =>{
let pass = true
if (pass) {
resolve("You have Passed third test")
} else {
reject("Sorry , better luck next time")
}
} )
let HR = new Promise((resolve,reject) =>{
let pass = true
if (pass) {
resolve("You have Passed final test")
} else {
reject("Sorry , better luck next time")
}
} )
let test = async (task,tech,manager,HR) => {
try {
let result = await task
result = await tech
result = await manager
result = await HR
console.log(result);
} catch (error) {
console.log(error);
}
}
// test(task,tech,manager,HR)
let check = new Promise((resolve,reject) => {
let isfail = true;
if (isfail) {
resolve("Oops, you are being reevaluated")
} else {
reject("Congrats, You have passed")
}
} )
let recheck = new Promise((resolve,reject) => {
let ispass = true;
if (ispass) {
resolve("You have passed reevaluation")
} else {
reject("Sorry , you have failed !")
}
})
let checkfn = async (check,recheck) => {
try {
let result = await check; // if promise is rejected, the next statement is NOT executed
console.log(result);
result = await recheck;
console.log(result);
} catch (error) {
console.log(error);
}
}
checkfn(check,recheck)