Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

84
Views
Cómo devolver solo un resultado al hacer una espera doble Node.js

Hola no encuentro solución a mi problema de funciones en cascada,

Servicio A

 print(await serviceB.methodA(myParameter));

Servicio B

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

Entonces la salida es

 undefined result

¿Cómo puedo esperar al segundo resultado del entonces? Porque cuando se vuelve indefinido está rompiendo mi servicio A

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Usando su estructura de código, necesita devolver la promesa interna.

Cambia esto:

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

a esto:

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

El resultado de .then() se convierte en el valor resuelto de la cadena de promesa. Como no devolvía nada del controlador .then() , ese valor resuelto se convirtió en undefined .


Pero, dado que está usando async/await , generalmente es mejor no mezclar también .then() en el mismo código, por lo que recomiendo cambiar a esto:

 async methodA(MyParameter){ let value = await methodB(MyParamter); return serviceA.methodC(value); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!