Node.js异步for循环未运行

时间:2019-12-19 20:19:38

标签: node.js asynchronous for-of-loop

我正在建立一个for循环,以将数据添加到Redis。由于所有Redis调用都是异步的,而且我不能仅添加JSON对象,因此我尝试使用for..of循环添加所有内容。我的问题是由于某种原因它没有运行循环。这是代码:

    var idObj =  {"id": profileId}         
    if(){     
    // this code is working fine
    } else {
    console.log('made it to the else statement');
    async function AsyncForLoop() {
      for (var key of Object.keys(idObj)) {
        console.log('in the for loop');
        await hsetAsync(profileId, key, idObj[key]); 
      }
      AsyncForLoop();
      json.status = "ok";
      res.send(JSON.stringify(json));
    };
  }

我可以进入“ make else to else语句”控制台日志,但是它实际上从未运行过for循环。我尝试使它成为异步函数,然后调用该函数,但它仍未运行。我什至没有收到res.send()的答复,在这里我想念什么?

0 个答案:

没有答案