Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

286
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda