-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync.js
48 lines (37 loc) · 828 Bytes
/
async.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
// console.log("Hello")
// setTimeout((a, b) => {
// console.log("hello")
// }, 2000)
// console.log("hii")
// function fetchData(callback) {
// setTimeout(() => {
// callback("Hello")
// }, 2000)
// }
// console.log("Starting console")
// fetchData((data) => {
// console.log(data)
// })
// console.log("Other data")
// Async and Await
let promise = new Promise((res, rej) => {
console.log("Before")
setTimeout(() => {
let age = 32;
if (age > 30) {
res("you eligible");
} else {
rej("not eligible");
}
}, 2000);
console.log("after")
});
async function getEligibility() {
try {
const result = await promise;
console.log(result);
} catch (err) {
console.log(err)
}
} 1
getEligibility();