-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPromise.js
53 lines (41 loc) · 1.29 KB
/
Promise.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
52
53
// let promiseCleanRoom = new Promise(function(resolve, reject){
// let cleanRoom = false;
// if(cleanRoom){
// resolve('clean');
// } else {
// reject('not clean');
// }
// });
// promiseCleanRoom.then(function(fromResolve){
// console.log('the room is ' + fromResolve)
// }).catch(function(fromReject){
// console.log('the room is '+ fromReject)
// });
let cleanRoom = function(){
return new Promise(function(resolve, reject){
resolve(' cleaned the Room ');
});
};
let removeGarbage = function(message){
return new Promise(function(resolve, reject){
resolve(message + ' remove the garbage');
});
};
let winIceCream = function(message){
return new Promise(function(resolve, reject){
resolve(message + ' won IceCream');
});
};
// cleanRoom().then(function(result){
// return removeGarbage(result);
// }).then(function(result){
// return winIceCream(result);
// }).then(function(result){
// console.log('finished' + result);
// })
// Promise.all([cleanRoom(), removeGarbage(), winIceCream()]).then(function(){
// console.log('all finished')
// });
Promise.race([cleanRoom(), removeGarbage(), winIceCream()]).then(function(){
console.log('one of them is finished') //one of them is finished
});