承诺里面的承诺不要等到Axios完成

时间:2019-05-10 16:41:43

标签: javascript node.js promise axios

我有麻烦了。我收到了许多对象,并在其中映射它们,并使用axios进行了外部咨询并保存了返回值,下面是代码:

   let savedClients = Object.entries(documents).map(personDocument => {
       let [person, document] = personDocument
       documentFormated = document
       documentNumbers = document.replace(/\D/g, '')

       return ConsultDocuments.getResponse(documentNumbers).then(resultScore => { // Calling the axios
           const info = { ...resultScore }
           return Save.saveClient(info)
       })
   })
   Promise.all(savedClients).then(results => {
       console.log(results) // Come only one document, repeted with the total documents passed in map
   })

问题是,它首先实现所有地图,然后多次仅对最后一个结果进行查询(通过的文档总数)

此代码是旧代码,使用async / await无效(严重,如果我不待在这里)

我尝试了N种方法来实现这一点,并且使用库Q(),它可以使地图按正确的顺序排列,但它并没有等到轴距,并且所有结果都带有“待定”状态

谢谢!

0 个答案:

没有答案