I have a problem with a closure in my loop. Here what I do :
this.newResults.cyclists.forEach(function(cyclist){
that.calcUsersScore( that.usersScoresByLigue,cyclist,bonus );
bonus--;
if(bonus === 0) {
console.log("c'est terminé");
that.addUsersScore( that.usersScoresByLigue );
}
});
So I want to execute my function addUsersScore()
with variable usersScoreByLigue
updated by precedent function calcUsersScore();
.
My problem is that this function calcUsersScore()
is long to execute (some requests with database and multiple tests) so how to wait for it and sure that addUsersScore()
fire after ?
Thanks in advance,