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

171
Vistas
Understanding await purpose within an async function in NODE

My question has to do with the await purpose in node.js. I'm going to write some dummy code in order to express my question, so please don't mind if there's something missing:

let f = async function(x) {
    var data = await readFile('x.txt');
    var link = openLink(`./myfile/${data}`);
    return link;
}

So, as I understand it, f will run in a separate thread from the Nodejs Event Loop while it expects the returning 'promised' value of link. When that new thread opens, the function gets executed synchronously within that thread - but if that's true, why bother with the await? I mean, the function content is executed from top to bottom, like in any synchronous programming language, so it already naturally "waits" for readFile to complete in order to continue to the next line and use data as a parameter.

I'm surely misunderstanding something here, but as I read articles and documentation about async await it doesn't get clearer for me why the await must be there.

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