Skip to content

Instantly share code, notes, and snippets.

@conanak99
Last active June 22, 2016 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conanak99/234485a3e68625158e4120f29f5702b9 to your computer and use it in GitHub Desktop.
Save conanak99/234485a3e68625158e4120f29f5702b9 to your computer and use it in GitHub Desktop.
// 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