Looking for advice on handling asynchronous calls within a loop, similar to the question addressed here. The key difference is that in this scenario, the asynchronous function is called multiple times within a loop.
The challenge lies in returning the value of 's'. Currently, the code returns undefined. This function is invoked within a for loop and utilizes the Bookshelfjs ORM library. Any suggestions or tips would be greatly appreciated!
function getUsernameFromDBAsync(userId) {
var s = "moo";
new Model.Users({
idUser: userId
})
.fetch()
.then(function(u) {
var prenom = u.get('firstName');
var nom = u.get('familyName');
s = prenom + " " + nom;
return s;
});
}