Skip to content

Commit 7da7ee0

Browse files
committed
promise
1 parent 74a1bb6 commit 7da7ee0

File tree

1 file changed

+68
-17
lines changed

1 file changed

+68
-17
lines changed

advance js/callback.js

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,77 @@
1+
//call back
2+
// function sum (a,b,sum){
3+
// return console.log(a+b)
4+
// }
5+
// function para(a,b,sum){
6+
// sum(a,b)
7+
// }
8+
// para(1,2,sum)
9+
10+
// function minus (a,b){
11+
// return console.log(a-b)
12+
// }
13+
// function cal(a,b,minus){
14+
// minus(a,b)
15+
// }
16+
// cal(5,1,minus)
17+
118
//callback hell
219

3-
function database(id,database){
4-
setTimeout(()=>{
5-
console.log("data of",id)
6-
if(database){
7-
database()
8-
}
9-
},2000)
20+
// function database(id,database){
21+
// setTimeout(()=>{
22+
// console.log("data of",id)
23+
// if(database){
24+
// database()
25+
// }
26+
// },2000)
1027

1128

1229

13-
}
14-
console.log("getting next data 3004")
15-
database(3004,()=>{
16-
console.log("getting next data 3005")
17-
database(3005,()=>{
18-
console.log("getting next data 3006")
19-
database(3006,()=>{
20-
console.log("getting next data 3007")
21-
database(3007)
22-
})
30+
// }
31+
// console.log("getting next data 3004")
32+
// database(3004,()=>{
33+
// console.log("getting next data 3005")
34+
// database(3005,()=>{
35+
// console.log("getting next data 3006")
36+
// database(3006,()=>{
37+
// console.log("getting next data 3007")
38+
// database(3007)
39+
// })
40+
// })
41+
// })
42+
43+
44+
//promise
45+
// function database(id,database){
46+
// return new Promise((resolve,reject)=>{
47+
// setTimeout(()=>{
48+
// console.log("data of",id)
49+
// resolve("success")
50+
// if(database){
51+
// database()
52+
// }
53+
// },5000)})
54+
// }
55+
56+
function getdata(id){
57+
return new Promise((resolve,reject)=>{
58+
setTimeout(()=>{
59+
console.log("data ",id)
60+
resolve("success")
61+
},3000)
62+
2363
})
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")
2472
})
2573

74+
75+
76+
2677

0 commit comments

Comments
 (0)