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

311
Vistas
Binding multiple callbacks for promises returns resolve value of first promise, not second

I have the following code as part of some coding practice I am doing:

var promise = new Promise(function(resolve, reject) {
    setTimeout(function() {
        resolve('hello world');
    }, 2000);
});

var promiseTwo = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve('hello again!');
    }, 2000);
});

promise.then(promiseTwo).then((data) => {
    console.log(data)
})

When the data is logged, it reads hello world and not hello again!. Why is that? My thinking was that the line promise.then(promiseTwo).then((data) => { console.log(data) }) would resolve the first promise, then pass the second promise in as a callback which would resolve to hello again!. Why does the resolve in promiseTwo never get return from the .then method?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Because you're not returning promiseTwo in then, you're simply calling it, try:

var promise = new Promise(function(resolve, reject) {
    setTimeout(function() {
        resolve('hello world');
    }, 2000);
});

var promiseTwo = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve('hello again!');
    }, 2000);
});

promise.then(() => promiseTwo).then((data) => {
    console.log(data)
})

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