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

88
Views
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 answers
Answer question

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 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!