I’m running into a problem using Asynchronous functions that return a task when used with Firestore. I’m trying to grab a QuerySnapshot from Firestore. Since Firestore returns queries asynchronously, I read that I needed to use a Async method that returns a task of type QuerySnapshot. I have the following code.
public async Task Get2()
{
orgRef = firestoreInstance.Collection(“organizations”);
Yes I have, and I have gotten those solution to output the database. If I have to, I’ll go back to their method, but I’m trying to get a return value and Visual Studio tells me I can’t return a value from anonymous functions or something. I’m not all that familiar with the limitations of anonymous functions, since I don’t make use of them much.
You can’t get a result immediately from an asynchronous operation, not without causing your game to freeze at least. That’s kind of the point. It finishes what it’s doing “sometime later”, so your code can’t expect a result immediately. You need to either use a callback function with ContinueWith or similar, or periodically check IsCompleted on the task, and only try to read the result after IsCompleted is true.