Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Cases Of Asynchronous Function

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!