-
-
Save conanak99/234485a3e68625158e4120f29f5702b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ba hàm này phải được thực hiện "cùng lúc" | |
// chứ không phải "lần lượt" | |
var sờ_trên = new Promise((resolve, reject) => { | |
resolve("Phê trên"); | |
}); | |
var sờ_dưới = new Promise((resolve, reject) => { | |
resolve("Phê dưới"); | |
}); | |
var sờ_tùm_lum = new Promise((resolve, reject) => { | |
resolve("Phê tùm lum chỗ"); | |
}); | |
// Truyền 1 array chứa toàn bộ promise vào hàm Promise.all | |
// Hàm này trả ra 1 promise, tổng hợp kết quả của các promise đưa vào | |
Promise.all([sờ_trên, sờ_dưới, sờ_tùm_lum]) | |
.then(function(result) { | |
console.log(result); // ["Phê trên", "Phê dưới", "Phê tùm lum chỗ"] | |
// Phê xong làm gì ai biết | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment