티스토리 뷰

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을 쓴다. 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함