1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
getSummonerInfo()
.then(summonerjson => {
console.log("getSummonerInfo 성공");
return getMatchInfo();
})
.then(matchjson => {
console.log("getMatchInfo 성공");
return getChampionInfo();
})
.then(championjson => {
console.log("getChampionInfo 성공");
return getItemInfo();
})
.then(itemjson => {
console.log("getItemInfo 성공");
//여기서 summonerjson matchjson championjson itemjson 사용하려면 어떻게 해야 함?
});
|
cs |
마지막에 summonerjson matchjson championjson itemjson 다 써야 하는데 어떻게 해야 하는거임..?
12개의 댓글
무분별한 사용은 차단될 수 있습니다.
뱀고기
Promise.all([getSummonerInfo(), getMatchInfo(), getChampionInfo(), getItemInfo()])
.then(function (values) {
var summoner = values[0];
var match = values[1];
var champion = values[2];
var item = values[3];
});
샤켓
감사감사
syntaxError
위에 받고 깔끔버전
Promise.all([getSummonerInfo(), getMatchInfo(), getChampionInfo(), getItemInfo()])
.then(function (values) {
const [summoner, match, champion, item] = values;
});
샤켓
와 감사
근데 잘 되던게 이걸로 바꾸니까
Uncaught (in promise) 200 parser error가 뜸..
샤켓
아...자바 내에서
컨트롤러 두개가 동시 실행되서 그러네...
SummonerInfo 컨트롤러 요청 실행되고 MatchInfo 가져와야대는데
둘이 같이 실행돼서..
안드로이드박사
프로미스 all이 순차실생 보장 안함
순차실행하는법 있긴한데 모바일이라 찾기 귀찮네
샤켓
잘 모르겠어서 그냥 하나만 콜백으로 바꿨어..
안드로이드박사
async await 써라
샤켓
프로미스 찾다가 그게 끝판왕이래서 해보고싶은데
이 글 같이 쓰는 예시 하나 써주면 안될까
안드로이드박사
집가서써줌 기달
안드로이드박사
const sampleF1 = async function() {
const summonerjson = await getSummonerInfo();
console.log("getSummonerInfo 성공");
const matchjson = await getMatchInfo();
console.log("getMatchInfo 성공");
const championjson = await getChampionInfo();
console.log("getChampionInfo 성공");
const itemjson = await getItemInfo();
console.log("getItemInfo 성공");
//여기서 summonerjson matchjson championjson itemjson 사용
}
const samleF2 = async function() {
const promises = [];
promises.push(getSummonerInfo());
promises.push(getMatchInfo());
promises.push(getChampionInfo());
promises.push(getItemInfo());
//Promise.All실행. 순서보장 안함 result에 리턴값이 담겨져있음
const result = await Promise.all(promises);
}
const samleF3 = async function() {
const promises = [];
let summonerjson;
let matchjson;
let championjson;
let itemjson;
promises.push(getSummonerInfo().then(result => summonerjson = result ));
promises.push(getMatchInfo().then(result => matchjson = result ));
promises.push(getChampionInfo().then(result => championjson = result ));
promises.push(getItemInfo().then(result => itemjson = result ));
//Promise리스트들을 순차실행
await promises.reduce(async (prevProm, postProm) => {
await prevProm;
await postProm;
}, Promise.resolve());
}
샤켓
와 감사감사
바꿔봐야지