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

85
Visualizações
How to return only one result when making a double await Node.js

Hi I can´t find a solution to my problem of functions in cascade,

Service A

print(await serviceB.methodA(myParameter));

Service B

async methodA(MyParameter){

            return await methodB(MyParamter).then((value) =>{
                serviceA.methodC(value);
               }

            
         );
    }

So the output is

undefined
result 

How I can wait to the second result of the then?? Because when getting undefined is broking my service A

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Using your code structure, you need to return the inner promise.

Change this:

async methodA(MyParameter){
    return await methodB(MyParamter).then((value) =>{
        serviceA.methodC(value);
    });
}

to this:

async methodA(MyParameter){
    return methodB(MyParamter).then((value) =>{
        return serviceA.methodC(value);
    });
}

The result of the .then() becomes the resolved value of the promise chain. Since you weren't returning anything from the .then() handler, that resolved value became undefined.


But, since you're using async/await, it is generally better to not also mix .then() in the same code so I'd recommend changing to this:

async methodA(MyParameter){
    let value = await methodB(MyParamter);
    return serviceA.methodC(value);
}
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