-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamPromise.js
38 lines (32 loc) · 1.12 KB
/
examPromise.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
const firstFunction = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('1')
resolve()
}, 3000)
})
}
const secondFunction = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('2')
resolve()
}, 1000)
})
}
const thirdFunction = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('3')
resolve()
}, 2000)
})
}
// โจทย์ข้อสุดท้ายให้ใช้ promise ในการช่วยให้ console.log ออกมาเรียงลำดับ 1 , 2 , 3 ตามลำดับ
// โดยไม่อนุญาติให้แก้เลขเวลาใน setTimeout โดยให้ เรียก firstFunction ก่อน หลังจากนั้นจึงตามด้วย
// secondFunction และ thirdFunction ตามลำดับ
(async () => {
await firstFunction()
await secondFunction()
await thirdFunction()
})()