티스토리 뷰
const promised = resultSearch.map(async (item) =>{
const _quadKey = item.quadKey;
const _longitude = item.center[0];
const _latitude = item.center[1];
const _getResponse = await tileQueryApi(_longitude, _latitude);
let _saveInfraPoint = 0;
_getResponse.data.features.map(item => {
const _maki = item.properties.maki;
const _mode = item.properties.mode;
const _stopType = item.properties.stop_type;
_saveInfraPoint += getInfraPoint(_maki, _mode, _stopType);
});
return {
quadKey: _quadKey ,
data: _saveInfraPoint
};
});
const awaitAllData = await Promise.all(promised);
자바스크립트 같은 경우 for문이 돌면서 await async를 실행해야 할 일이 있다.
이때 그냥 map이든 for이든 돌려도 제대로 안돌아간다.
이때 Promise.all을 쓴다.
'프로그래밍 > 자바스크립트 ' 카테고리의 다른 글
소수점 2자리 까지만 허용하는 정규표현식 (0) | 2022.02.16 |
---|---|
react, JS의 반복문에서 await, async가 동기적으로 작동하지 않을때 (0) | 2022.01.20 |
mapbox - production환경에서 에러가 날때 (0) | 2022.01.19 |
전 지구를 10m 단위로 쪼개는 방법 (0) | 2021.11.30 |
리액트 동적 이미지 적용하기 (0) | 2021.05.18 |