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

248
Views
What is the reason the Async function that I have below is returning Promise { <pending> } instead of returning the proper value?

When I console.log() paymentsResults and pendingResults from the code below, I can see the data being logged properly. However, right at the last moment when I am trying to return payments and pending I see the results as Promise { <pending> } in my backend. What is the reason and how can I fix the issue here?

const query = await pool.query(q);

const payments = query.rows.filter(o => getCategory(o) === "payment");
const pending = query.rows.filter(o => getCategory(o) === "pending");
const inactive = query.rows.filter(o => getCategory(o) === "inactive");

const paymentsResults = payments.map(async order => {

    const A = ({
        date: getDate(order),
        item: await getItem(order),
        total: getTotal(order),
        purchaser: getPurchaser(order),
        email: getEmail(order),
        paymentMethod: getPaidUsing(order),
        status: getStatus(order)
    });
    return A;
});



const pendingResults = pending.map(async order => {

    const B = {
        date: getDate(order),
        item: await getItem(order),
        total: getTotal(order),
        purchaser: getPurchaser(order),
        email: getEmail(order),
        status: getStatus(order)
    };

    return B;
});


return {
    payments: paymentsResults,
    pending: pendingResults,
    inactive: inactive
};
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

const paymentsResults = await Promise.all(payments.map(async order => {
    const A = {
        date: getDate(order),
        item: await getItem(order),
        total: getTotal(order),
        purchaser: getPurchaser(order),
        email: getEmail(order),
        paymentMethod: getPaidUsing(order),
        status: getStatus(order)
    };

    return A;
}));


const pendingResults = await Promise.all(pending.map(async order => {
    const B = {
        date: getDate(order),
        item: await getItem(order),
        total: getTotal(order),
        purchaser: getPurchaser(order),
        email: getEmail(order),
        status: getStatus(order)
    };

    return B;
}));

  • array of Promise should be resolved by Promise.all before using.
  • async function always returns promise.
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!