File tree Expand file tree Collapse file tree 1 file changed +35
-12
lines changed
Expand file tree Collapse file tree 1 file changed +35
-12
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments