-
Notifications
You must be signed in to change notification settings - Fork 0
/
Promises.js
44 lines (35 loc) · 848 Bytes
/
Promises.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
console.log("start")
// function loginUser(user, callback){
// setTimeout(() => {
// callback(user.toUpperCase())
// }, 1000);
// }
// function getVideos(user, callback){
// setTimeout(()=>{
// callback(['video1', 'video2'])
// }, 500)
// }
// loginUser("Asad", user=>{
// console.log("Welcome", user)
// getVideos((user), videos=> console.log(videos))
// })
// promise
function loginUser(user){
return new Promise((resolve)=>{
setTimeout(() => {
resolve(user.toUpperCase())
}, 1000);
})
}
function getVideos(){
return new Promise((resolve)=>{
setTimeout(()=>{
resolve(['video1', 'video2'])
}, 500)
})
}
loginUser("Asad")
.then(res => console.log(res))
.then(() => getVideos())
.then(res => console.log(res))
console.log("end")