-
Notifications
You must be signed in to change notification settings - Fork 0
/
promises ex.js
51 lines (46 loc) · 1.45 KB
/
promises ex.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
45
46
47
48
49
50
51
// waiting for wife to show the tickets in queue
console.log('person1: shows ticket');
console.log('person2: shows ticket');
// person 3 is waiting for wife to get the tickets
//const wifeBrinsTickets= new Promise((resolve,reject)=>{
// setTimeout(()=>{
// resolve('tickets');
// },2000);
//})
//
//const popcorn = wifeBrinsTickets.then((t)=>{
// console.log('person3:');
// console.log('wife: i have the tickets');
// console.log('husband: we should go in');
// console.log('wife: i am hungry');
// return new Promise((resolve ,reject)=>resolve(`${t} popcorn`));
//
//})
//
//const drink=popcorn.then((t)=>{
// console.log('husband: we should go in');
// console.log('wife: i want some drink');
// return new Promise((resolve,reject)=>resolve(`${t} drinnk`))
//})
//
//drink.then((t)=>console.log(t));
// conventional way is
new Promise((resolve,reject)=>{
setTimeout(()=>{
resolve('tickets');
},2000);
})
.then((t)=>{
console.log('person3:');
console.log('wife: i have the tickets');
console.log('husband: we should go in');
console.log('wife: i am hungry');
return new Promise((resolve ,reject)=>resolve(`${t} popcorn`));
})
.then((t)=>{
console.log('husband: we should go in');
console.log('wife: i want some drink');
return new Promise((resolve,reject)=>resolve(`${t} drinnk`))
}).then((t)=>console.log(t));
console.log('person4: shows ticket');
console.log('person5: shows ticket');