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

134
Views
El método asíncrono no espera esperar, devuelve indefinido en su lugar

Actualmente estamos digitalizando un juego de póquer de planificación. Cuando todos los usuarios enviaron su voto, debe verificar si la mayoría de los usuarios enviaron una tarjeta de café, que tiene un valor de -1.

Los métodos recuperan los votos de todos de una base de datos Mongo así:

 async checkCoffeeTimeout() { let coffeeVotes = 0; // Get the votes from the database await this.updateDBData() .then(response => { this.dbData = response[0]; let feature = this.dbData.features[this.featurePointer]; let half = 1; if(feature !== undefined) // Waiting state has no features yet { half = feature.votes.length / 2 feature.votes.forEach(vote => vote.value == -1 ? coffeeVotes++ : ''); } return coffeeVotes >= half; }); }

Por alguna razón, el método no esperará la promesa this.updateDBData() , que es:

 updateDBData() { return SessionObject.find({_id: this.dbData._id}) }

Llamar a checkCoffeeTimeout() en un método asíncrono, precedido por un await todavía devuelve undefined.

¿Me estoy perdiendo de algo? Soy bastante nuevo en la forma de promesas await/async

about 4 years ago · Juan Pablo Isaza
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!