Look, i have an app using live updates from Firestore for the authenticated user, the app settings and some locations.
My code looks like this:
firestore
.collection("settings")
.doc("client")
.onSnapshot(
(doc) => {
settingContext.setSetting(doc.data());
}
);
firestore
.collection("users")
.doc(user.uid)
.onSnapshot(
(doc) => {
authContext.updateLoggedInUser({ id: user.uid, ...doc.data() });
}
);
But i also, request some other information to Firestore in the same function (initApp). The last request in this function lets the app know is ready to launch, but the problem here is that, at this point, is difficult to know if the three onSnapshots have returned data, and this data is needed to condition the screens in my app.
So i've been trying to create workarounds to make this work inline and what i mean by inline is to execute all request and get the data in the order i set them in the code.
I know this is quite hard, because the response of snapShots depends on various factors (internet speed for example).
I tried to wrap this calls inside a Promise(Just to be able to await them) and resolve once i receive data, but as you might guess, this will only return data once and i need to continue receiving live updates.
Any suggestions?