Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda