I\'m looking to build function to wait until all values in on(\'value\') will be set and then go to the next line, in other words async function.
let upcomi
-
Firebase's on()
function will continuously listen to the location that you call them on. That means that they can give you data multiple times. Since a Promise
can only resolve once, on()
does not return a promise. And thus it can't be used with async
/await
.
In this case it looks like you'll want to use once()
, which works pretty much the same but will only deliver a result once (and thus returns a promise):
let upcomingGamesList = await firebase.database().ref('UpcomingGames').once('value', snapshot => {
upcomingGamesList = snapshot.val()
console.log('upcoming t2',upcomingGamesList)
return upcomingGamesList
})
讨论(0)
- 热议问题