In this opportunity I call a database in firebase
, but to give it a timely and thus be almost sure that the data is loaded I use a promise
with a setTimeout
as follows;
var base = [];
var promise = new Promise((res,err)=>{
const db = firebase.database().ref().child('price');
db.on('value', snap => base.push(snap.val()));
setTimeout(res, 3000);
});
promise.then(()=>{
console.log(base[0]);
});
I'm really something new with JavaScrit
I know I'm not really making sure the data is already based on the promise, my question is how to do it? how to do to know that 'firebase' has already returned the data.
thanks!