Skip to content

Commit fff010d

Browse files
committed
asyn await
1 parent 7da7ee0 commit fff010d

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

advance js/callback.js

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,48 @@
5353
// },5000)})
5454
// }
5555

56-
function getdata(id){
56+
// function getdata(id){
57+
// return new Promise((resolve,reject)=>{
58+
// setTimeout(()=>{
59+
// console.log("data ",id)
60+
// resolve("success")
61+
// },3000)
62+
63+
// })
64+
// }
65+
66+
// getdata(1).then((res)=>{
67+
// return getdata(2)
68+
// }).then((res)=>{
69+
// return getdata(3)
70+
// }).then((res)=>{
71+
// console.log("success")
72+
// })
73+
74+
75+
//asyn await
76+
77+
function api(id){
5778
return new Promise((resolve,reject)=>{
5879
setTimeout(()=>{
59-
console.log("data ",id)
80+
console.log("data of",id)
6081
resolve("success")
82+
6183
},3000)
6284

85+
6386
})
6487
}
6588

66-
getdata(1).then((res)=>{
67-
return getdata(2)
68-
}).then((res)=>{
69-
return getdata(3)
70-
}).then((res)=>{
71-
console.log("success")
72-
})
73-
74-
75-
89+
(async function fun (){
90+
console.log("fetching data1.......")
91+
await api(1)
92+
console.log("fetching data2.......")
93+
await api(2)
94+
console.log("fetching data3.......")
95+
await api(3)
96+
console.log("fetching data4.......")
97+
await api(4)
98+
})();
7699

77100

0 commit comments

Comments
 (0)