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

246
Vistas
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 Respuestas
Responde la pregunta

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