0

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

  • `SessionObject.find({_id: this.dbData._id})` should return a promise that will be *awaited* for. And you don't need to apply `then` since you are using async/await. – Nizar Zizoune Dec 02 '21 at 08:52
  • `checkCoffeeTimeout` does not return anything. The callback to `then` returns something, but that doesn't go anywhere. Don't mix `await` and `then`, use one or the other (prefer `await`). – deceze Dec 02 '21 at 08:54
  • Oh now i see, thanks! – SeasideCoding Dec 02 '21 at 09:06

0 Answers0