This is my code currently
function resolveAfter1() {
return new Promise((resolve, reject) => {
var scoresFromDb = db.account.find({}, { username: 1, score: 1 }).toArray(function(err, result) {
if (err)
reject(err);
else
resolve(result);
});
});
}
resolveAfter1() // resolve function
.then((result)=>{console.log(result);})
.catch((error)=>{console.log(error);})
async function asyncCall() {
var result = await resolveAfter1();
// console.log(result);
}
When I do socket emit, I get [object Object]instead of the values, this is my Emit on the server
socket.emit('allScores', asyncCall());
Then this is my socket.on on the client side HTML
socket.on('allScores', function(data){
console.log(data);
})
The answer I am getting in the chrome console is this
{}
Can anyone tell me why it's not displaying asyncCall() like this? this is what I get in the server which is perfect, but when I emit and receive it with the socket on, I don't get this?
[ { _id: 5a7c6552380e0a299fa752d3, username: 'test', score: 44 } ]