You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use asyncawait and do not manage to make it works. I apologize for my question which answer should be obvious...
The part of the program after await is not executed at all. What should I do to leave the function concerned by await once it has been executed ?
If required (node v6.11 & asyncawait@lastest)
Many thanks
joinArrayRooms(roomNames)
const joinArrayRooms = async (function(roomNames){
let newRoomNames = []
console.log('roomNames : ',roomNames)
await(function(){
for(let i_roomNames=0;i_roomNames<roomNames.length;i_roomNames++){
socket.join(roomNames[i_roomNames],function(){
newRoomNames.push(roomNames[i_roomNames])
// send to peers my new info
console.log('roomName : ', roomNames[i_roomNames])
socket.broadcast.to(roomNames[i_roomNames]).emit('sendRoomData','test_data')
})
}
})
// THIS PART IS NOT EXECUTED
// update array of rooms on client side
console.log('joinRoom_emit : ',newRoomNames)
return socket.emit('joinRoom',newRoomNames)
// TODO store the data in the dB
})
The text was updated successfully, but these errors were encountered:
The problem is with the await(...) call. The await function is expecting a promise as an argument, but you are passing it a function. This invokes some little-used behaviour in this library (not the behaviour you were intending) and in short joinArrayRooms never resumes.
The proper way to do this it to take out the await call around the for loop, and put await calls around the things that are async, like socket.join(...). But for that to work, you need socket.join to return a promise (you can use promisify for that).
Hello,
I am trying to use asyncawait and do not manage to make it works. I apologize for my question which answer should be obvious...
The part of the program after await is not executed at all. What should I do to leave the function concerned by await once it has been executed ?
If required (node v6.11 & asyncawait@lastest)
Many thanks
The text was updated successfully, but these errors were encountered: