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

149
Views
Usar await no es esperar a que se resuelva una Promesa, ¿puede decirme por qué me enfrento a este comportamiento?

Tengo una función como esta,

 const getCurrentDetails= async () => { const currentDateTime = new Date(moment('00:00','HH:mm') .tz('America/New_York') .toISOString()); const currentDateDetail = await getDetailsForTimestamp(currentDateTime); console.log("currentDateDetail: ",currentDateDetail) //prints PromiseProvider {} if(currentDateDetail){ //do some stuff if details present } }

Aunque estoy usando await para resolver la promesa antes de ir al siguiente paso , aún así registra PromiseProvider {} en el siguiente paso y la siguiente verificación de condición no se valida correctamente.

Tenga en cuenta que la misma función funciona bien a veces, pero no es consistente ya que enfrento el comportamiento mencionado anteriormente muchas veces, estoy usando el nodo 16 y aquí está la función getDetailsForTimestamp.

 const getDetailsForTimestamp = async (currentTimeStamp) => { const { db } = await database.getDb(process.env.DB_NAME); if (db) { return new Promise((resolve, reject) => { db.collection(process.env.COLLECTION_NAME) .findOne({ updatedAt: { $gte: currentTimeStamp } }) .then((res) => { resolve(res); }) .catch((err) => { reject(err); }); }); } };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

¿Por qué no usas simplemente

 async await instead of Promise

Intente reemplazar su método "getDeatilsForTimestamp" con esto:

 const getDetailsForTimestamp = async currentTimeStamp => { const { db } = await database.getDb(process.env.DB_NAME); if (db) { try { return await db .collection(process.env.COLLECTION_NAME) .findOne({ updatedAt: { $gte: currentTimeStamp } }); } catch (e) { return e; } } };
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!