Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
Async method not waiting for await, returns undefined instead

We're currently digitizing a planning poker game. When all users submitted their vote, it should check if the majority of users submitted a coffee card, which has a value of -1.

The methods retrieves everyones votes from a Mongo database like so:

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;
            });
}

For some reason the method won't await the promise this.updateDBData(), which is:

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

Calling the checkCoffeeTimeout() in an async method, prepended by an await still returns undefined.

Am i missing something? I'm quite new to the await/async way of promises

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda