0

I am working with dns resolve function. I have a code structure as below. The function completes without waiting for the dns resolve foreach structure to complete. this problem is caused by dns.resolve function because when i remove it everything works as it should. The dns resolver has a promise structure, but I wanted to set up such a structure so that the records do not wait for each other. how can i solve the problem?

  var resData = [];

    var funcs = async() => {
      await func1();
      await func2();
    }
  
    var func1 = async() => {
          querys.forEach((element) => {
              dns.resolve(element.queryDomain, element.queryType, (err, records) => {
                  if (err) {
                    console.log(err);
                  }
                  else{
                       resData.push({ type: element.sendType, value: records});
                  }
              });
          });
    } 
  
    var func2 = async() => {
      console.log(resData);
    }


funcs();  

output = [] it mean empty

aliveli49
  • 31
  • 4

0 Answers0