I am initiating several callback functions inside a function. I don't want the parent function to return any value before all the callback functions have returned it's response.
I have tried this, without any luck:
function getList(userList) {
let tempArray = []
let allAboard = false
userList.map((users, usersIndex) => {
users.map((user, userIndex) => {
HTTP.get(SOME API CALL, function(response){
tempArray.push({'user': user.id, 'elements': response.data})
if (tempArray.length === (userList.length * users.length)){
allAboard = true
}
})
})
})
while(!allAboard) {
if (allAboard) {
break
}
}
return tempArray
}
Any idea how to make this work?