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

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

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