Created
July 13, 2019 16:01
-
-
Save ohoroyoi/3c4caf7470a9b0a2195be908451a141f to your computer and use it in GitHub Desktop.
Promise.all 예시
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
const getTodos = (id) => { | |
return new Promise((resolve, reject) => { | |
$.getJSON(`https://jsonplaceholder.typicode.com/todos/${id}`, (data) => { | |
resolve(data); | |
console.log(data); | |
}); | |
}); | |
} | |
Promise.all([ | |
getTodos('1'), | |
getTodos('2'), | |
getTodos('3'), | |
]); | |
// 다 받는거 확신해야할떄 | |
Promise.all([ | |
getTodos('1'), | |
getTodos('2'), | |
getTodos('3'), | |
]).then((dataArr) => { console.log(dataArr) }); | |
// dataArr는 항상 순서대로 출력. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment