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

103
Vistas
How do I resolve nested promises in an object

Code:

async function main() {
  const arr = [];
  symbols.forEach((symbol) => {
    const record = {
      [symbol]: {
        quote: priceQuote(token, symbol),
        history: makePriceHistoryRequest(token, symbol, slow * 2),
      }
    }
    arr.push(record);
  })
    return arr;
}

I call main as follows:

main().then(res=>{
  console.log(res);
})

It returns quote and history as Promise. How can I get into nested pending promise?

Thanks!

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

0

If quote and history are promises it means that priceQuote and makePriceHistoryRequest are functions that return promises, in this case, you need to make the callback that iterates them async, not the wrapper:

 function main() {
   return Promise.all(symbols.map(async (symbol) => {
     const record = {
      [symbol]: {
        quote: await priceQuote(token, symbol),
        history: await makePriceHistoryRequest(token, symbol, slow * 2),
      }
    }
    return record
  })  
}

main().then(value => console.log(value) ) 
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