I have a function that completes two await tasks, one that grabs info from a database in the cloud, another that grabs the users location. The function should return a promise that contains the results of both of these tasks. For some reason, the promise will only return the result of the first await (database...), not the second (Geolocation...)
. Here is some code that is related to the problem.
async function grabUserData(): Promise<Object> { const data = { position: {Latitude: 0, Longitude: 0}, altitude: 0, altitudeAccuracy: 0, timestamp: Timestamp.now(), }; await database .collection('users') .doc(userUID) .get() .then((doc) => { if (doc.exists) {'does some work here' (which works fine) } else { console.log('No such document!'); } }); await Geolocation.getCurrentPosition((position) => { data.position.Longitude = position.coords.longitude; data.position.Latitude = position.coords.latitude; if (position.coords.altitude != null) { data.altitude = position.coords.altitude; } if (position.coords.altitudeAccuracy != null) { data.altitudeAccuracy = position.coords.altitudeAccuracy; } }); return new Promise(function (resolve) { resolve(data); });}
Update: Geolocation.getCurrentPosition does NOT return a promise therefore it shouldn't have await next to it. However, even with removing it, it does not change anything related to the problem I'm having. I actually put it there because I thought by awaiting it, it would not be skipped over and return incomplete data.