Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

115
Vistas
"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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda