Skip to content

Instantly share code, notes, and snippets.

@ohoroyoi
Created July 13, 2019 16:01
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 ohoroyoi/3c4caf7470a9b0a2195be908451a141f to your computer and use it in GitHub Desktop.
Save ohoroyoi/3c4caf7470a9b0a2195be908451a141f to your computer and use it in GitHub Desktop.
Promise.all 예시
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