-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromisefunction.js
56 lines (48 loc) · 1.13 KB
/
promisefunction.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
54
55
56
// function promise1(){
// return new Promise((resolve, reject) =>{
// setTimeout(() =>{
// resolve('hello promise 1')
// },1);
// });
// }
// function promise2(){
// return new Promise((resolve, reject) =>{
// setTimeout(() =>{
// resolve('hello promise 2')
// },1);
// });
// }
// async function result(){
// console.log("start");
// await Promise.all([await promise1(),await promise2()]).then(value=>{
// console.log('Promise all' ,value);
// })
// console.log("end");
// }
// result();
function data(){
return new Promise((resolve, reject)=>{
setTimeout(() => {
resolve('food')
},1);
});
}
function datafill(){
return new Promise((resolve, reject)=>{
setTimeout(() => {
resolve('data fill hello')
},1);
}).then(value =>{
console.log('value =', value);
return value;
})
}
async function output(){
console.log('start');
let obj = await data();
console.log(obj);
let obj1 = await datafill();
console.log(obj1);
console.log('end');
}
output();