cachapa / firedart

A dart-native implementation of the Firebase Auth and Firestore SDKs
https://pub.dev/packages/firedart
Apache License 2.0
174 stars 62 forks source link

issue with delete() followed by listen() #86

Open tpham3783 opened 2 years ago

tpham3783 commented 2 years ago

Hi,

I am observing an issue with synchronous access between a delete and listen.

take this code for example:

await docRef.delete();

CollectionReference mRef = await cRef.collection("CollectionOfPrevDoc");

/* listen for changes of all docs */
StreamSubscription sub = await mRef.stream.listen((event) {
          // the deleted doc (docRef), would get called back here, 10% of the time, 
          // even though it was deleted using a synchronous call.  
    });

Would someone please advise why this would happen and how to fix it?

tpham3783 commented 2 years ago

I traced down the delete method, and it looks like it is an asynchronous call to grpc:

  Future<void> deleteDocument(String path) => _client
      .deleteDocument(DeleteDocumentRequest()..name = path)
      .catchError(_handleError);

I am not sure how to make that call synchronous, given it is a grpc api.