-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path50 async-await.js
More file actions
68 lines (59 loc) · 1.42 KB
/
50 async-await.js
File metadata and controls
68 lines (59 loc) · 1.42 KB
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
//normal promise function
let text=new Promise((res,rej)=>{
let s;
let a=12;
let b=2;
s=a+b;
if (a!=b){
return res(`normal promise ${s}`);}
else{
return rej(a);}
});
text.then((value)=>console.log("then ",value)).catch((value)=>console.log("catch ",value));
//async function
async function sum(a,b) {
let s;
s=a+b;
if (a==b){
return Promise.resolve(`async function ${s}`);}
else{
return Promise.reject(`async function ${a}`);}
}
sum(12,2).then((value)=>console.log("then ",value)).catch((value)=>console.log("catch ",value));
async function show() {
let promise=new Promise((response,reject)=>{
setTimeout(() => {
return response("done!");
}, 3000);
});
let result=await promise;
console.log(result);
}
show();
/*
async function show() {
let promise=new Promise((response,reject)=>{
setTimeout(() => {
return response("done!");
}, 3000);
});
try {
let value=await promise;
console.log("then",value);
} catch (error) {
}*/
async function show1() {
let x=new Promise((resolve,reject)=>{
setTimeout(() => {
resolve("rana g");
}, 3000);
});
let s= await x;
console.log(s);
// x.then((a)=>{console.log("welcome ",a)});
try {
console.log("welcome to ",s);
} catch (error) {
}
}
show1();