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

108
Views
"asyncing" new Promise( resolve, reject )

Basically what you see me doing here is "asyncing" a promise that I'm just creating.

Is that some unadvisable, anti-pattern, fatal flow, or silly way to write a promise? If so, why?

function returnSomething(name) {

  return new Promise(async (resolve, reject) => {

    try {

       //some dealings....
 
       const somethingElse = await returnSomethingElse();

       //do some stuff with 'somethingElse'

       resolve(somethingElse);
    
    } catch(error) {

       //some dealings....

       reject(error);
       return;

    }

  });

}

The temptation to do this is basically very easy to explain. I want to avoid the .then().then().then() hell if I return a promise as a result from a promise.

I also wanted to avoid working with something like this:

function returnSomething(name) {

  return new Promise((resolve, reject) => {

       //some dealings....
 
       returnSomethingElse().then((somethingElse) => { 

          //do some stuff with 'somethingElse'

          resolve(somethingElse); 

       }).error((error) => {

          //some dealings....

          reject(error);
          return;
       });
    }

  });

}

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
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!