[Firestore] Asynchronous methods from library hang and don't return anything.
See original GitHub issueHello. I am trying to incorporate Cloud Firestore into a C# application. I created the async method below (and I call it from the main method of my application):
public async Task firebaseStuff()
{
FirestoreDb db = FirestoreDb.Create(projectId);
CollectionReference collection = db.Collection("users");
QuerySnapshot allUsers = await collection.GetSnapshotAsync();
MessageBox.Show("Done Querying!");
return;
}
The users collection only has one document. The GetSnapshotAsync()
method doesn’t seem to return anything and the “Done Querying!” box never shows. Am I missing something?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
Retry asynchronous functions | Cloud Functions for Firebase
This document describes how you can request asynchronous (non-HTTPS) background functions to retry on failure. Semantics of retry.
Read more >angular - Async method does not return a value and is stuck
So if this.fireAuth.authState never completes, but emits values you can use the first operator to create a stream that completes after the first ......
Read more >Troubleshoot Cloud Functions
Some Cloud Logging client libraries use an asynchronous process to write log entries. If a function crashes, or otherwise terminates, it is possible...
Read more >Cloud Firestore
The collection method returns a CollectionReference class, which provides properties and methods to query and fetch the data from Cloud Firestore.
Read more >Why are the Firebase API asynchronous?
It's easy to spot them because their API docs show that they don't directly return the data you want. Instead, they'll return things...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Right, the constructor itself can’t be asynchronous - but you can call a static factory method which is asynchronous, does all the async work, and then constructs an instance:
I don’t know whether that will be the right solution for you or not, but it’s one option to consider.
What’s more important is that you understand why your previous code failed - by calling
Wait()
, you were saying “I’m not going to let the WPF dispatcher thread do anything else until the task returned byfirebaseStuff
has completed”. Unfortunately, thefirebaseStuff
method has said “When the task returned by AddAsync completes, I need to come back to the WPF Dispatcher thread in order to return and set the task result”. That’s why you’ve got a deadlock.I’m going to close this issue now as it really isn’t related to Firestore or the client library - it’s just a matter of working correctly with async methods.
The app itself is a WPF app. I am calling the method from within the
MainWindow.xaml.cs
constructor which isn’t (and can’t be, to my knowledge) async. I just tried without.Wait()
and it seems to have worked? I’m going to try and test it a few more ways before confirming.EDIT: Yeah, it works. Thank you for explaining what I did wrong.