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

282
Vistas
AWS Lambda - NodeJS - nested Await / Async not returning

Having this small Lambda-Function:

module.exports.handler = async( data , ctx, cb) => {
 console.log("start");
 createSth();
};


async function resolveAfter2Seconds(x) {
  console.log("in function: " + x);
  return new Promise(resolve => {
    setTimeout(() => {
      resolve(x);
    }, 2000);
  });
}

async function createSth() {
  var x = await resolveAfter2Seconds(10);
  console.log(x); // 10
}

I would have expted the following output

start
in function: 10
10

But I only get

start
in function: 10

So everything after var x = await resolveAfter2Seconds(10); is not executed.

It works outside of aws lambda in a similar setup.

Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Add await keyword while calling createSth function. This will allow main function to wait for the execution of the function and won't return

i.e.

module.exports.handler = async( data , ctx, cb) => {
    console.log("start");
    await createSth();
};
about 4 years ago · Juan Pablo Isaza Denunciar
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