Skip to content

Port FSTAsyncQueryListener to C++ #2620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 50 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
433fec1
Replace FSTDocumentSet's guts with immutable::SortedSet.
wilhuff Mar 17, 2019
83d61c7
Port FSTDocumentSet to C++ DocumentSet.
wilhuff Mar 17, 2019
5666ce5
Replace implementation of FSTDocumentSet with C++ DocumentSet
wilhuff Mar 21, 2019
83c0687
Update all usages of FSTDocumentSet
wilhuff Mar 17, 2019
614132f
Remove FSTDocumentSet
wilhuff Mar 21, 2019
d648e35
Merge branch 'master' into wilhuff/document-set
wilhuff Mar 22, 2019
f46866c
Add Objective-C++ guard
wilhuff Mar 22, 2019
3f45e44
Use absl::c_equal instead of hand-rolling it.
wilhuff Mar 22, 2019
c4fbcfe
Split SortedContainer out of SortedMapBase
wilhuff Mar 23, 2019
114fe05
Remove = default constructors that aren't true.
wilhuff Mar 23, 2019
03847dc
Fix NSNotFound -> npos
wilhuff Mar 23, 2019
9d86b35
Fix usage of FSTQuery.limit
wilhuff Mar 23, 2019
5cbe0ea
Port FSTListenOptions to C++
wilhuff Mar 23, 2019
b2116b3
Remove usage of FSTListenOptions
wilhuff Mar 23, 2019
59da887
Remove FSTListenOptions
wilhuff Mar 23, 2019
2a6685d
Add QueryListener
wilhuff Mar 23, 2019
b23a5a2
Replace FSTQueryListener with C++ QueryListener
wilhuff Mar 24, 2019
99aed48
Implement ListenerRegistration in C++
wilhuff Mar 23, 2019
aec554a
Reimplement FSTListenerRegistration with C++ ListenerRegistration
wilhuff Mar 24, 2019
786e2f1
Test that shows a leak.
wilhuff Mar 17, 2019
bf2e76a
Add EventListener to match Android.
wilhuff Mar 17, 2019
c7a9a3e
Use AsyncEventListener in FSTQueryListenerTests
wilhuff Mar 24, 2019
768d0c5
Use EventListener throughout
wilhuff Mar 24, 2019
d52ef3b
Remove FSTAsyncQueryListener
wilhuff Mar 24, 2019
8dd6bfc
Review feedback
wilhuff Mar 25, 2019
6f87468
Merge branch 'wilhuff/listen-options' into wilhuff/query-listener
wilhuff Mar 25, 2019
1011a72
Merge branch 'wilhuff/query-listener' into wilhuff/listener-registration
wilhuff Mar 25, 2019
f2b254b
Review feedback
wilhuff Mar 25, 2019
b64a88b
Merge branch 'wilhuff/listener-registration' into wilhuff/async-listener
wilhuff Mar 25, 2019
3c5cd51
Merge branch 'master' into wilhuff/listen-options
wilhuff Mar 25, 2019
1f6c482
Merge branch 'master' into wilhuff/listen-options
wilhuff Mar 25, 2019
ed184d6
Merge branch 'wilhuff/listen-options' into wilhuff/query-listener
wilhuff Mar 25, 2019
9de0d8f
Merge branch 'wilhuff/query-listener' into wilhuff/listener-registration
wilhuff Mar 25, 2019
6e7064f
Merge branch 'wilhuff/listener-registration' into wilhuff/async-listener
wilhuff Mar 25, 2019
a39902e
Add QueryListener
wilhuff Mar 23, 2019
ce97b90
Replace FSTQueryListener with C++ QueryListener
wilhuff Mar 24, 2019
03157ff
objc::unordered_map
wilhuff Mar 26, 2019
ba38b49
Add a lint check for Objective-C banned words
wilhuff Mar 26, 2019
d85bf4e
Review feedback
wilhuff Mar 26, 2019
000bc1a
Merge branch 'master' into wilhuff/query-listener
wilhuff Mar 26, 2019
2835378
Merge branch 'wilhuff/query-listener' into wilhuff/listener-registration
wilhuff Mar 26, 2019
73cfad7
Merge branch 'wilhuff/listener-registration' into wilhuff/async-listener
wilhuff Mar 26, 2019
f186fd1
style.sh generated changes
wilhuff Mar 26, 2019
58b4b97
lint fixes
wilhuff Mar 26, 2019
f6a7b65
Fix CMake build
wilhuff Mar 26, 2019
043db66
Merge branch 'wilhuff/query-listener' into wilhuff/listener-registration
wilhuff Mar 26, 2019
903fbdf
Merge branch 'wilhuff/listener-registration' into wilhuff/async-listener
wilhuff Mar 26, 2019
5a2540d
Merge branch 'master' into wilhuff/async-listener
wilhuff Mar 26, 2019
aaa2abe
Review feedback
wilhuff Mar 26, 2019
2682adc
Remove ListenerRegistration default constructor
wilhuff Mar 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions Firestore/Example/Tests/Core/FSTEventManagerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,26 @@
#include "Firestore/core/src/firebase/firestore/util/statusor.h"
#include "Firestore/core/test/firebase/firestore/testutil/xcgmock.h"

using firebase::firestore::core::EventListener;
using firebase::firestore::core::ListenOptions;
using firebase::firestore::core::ViewSnapshot;
using firebase::firestore::core::ViewSnapshotHandler;
using firebase::firestore::model::DocumentKeySet;
using firebase::firestore::model::DocumentSet;
using firebase::firestore::model::OnlineState;
using firebase::firestore::util::StatusOr;
using firebase::firestore::util::StatusOrCallback;
using testing::ElementsAre;

NS_ASSUME_NONNULL_BEGIN

namespace {

ViewSnapshotHandler NoopViewSnapshotHandler() {
return [](const StatusOr<ViewSnapshot> &) {};
ViewSnapshot::Listener NoopViewSnapshotHandler() {
return EventListener<ViewSnapshot>::Create([](const StatusOr<ViewSnapshot> &) {});
}

std::shared_ptr<QueryListener> NoopQueryListener(FSTQuery *query) {
return QueryListener::Create(query, NoopViewSnapshotHandler());
return QueryListener::Create(query, ListenOptions::DefaultOptions(), NoopViewSnapshotHandler());
}

} // namespace
Expand Down Expand Up @@ -112,17 +113,14 @@ - (void)testNotifiesListenersInTheRightOrder {
FSTQuery *query2 = FSTTestQuery("bar/baz");
NSMutableArray *eventOrder = [NSMutableArray array];

auto listener1 = QueryListener::Create(query1, [eventOrder](const StatusOr<ViewSnapshot> &) {
[eventOrder addObject:@"listener1"];
});
auto listener1 = QueryListener::Create(
query1, [eventOrder](StatusOr<ViewSnapshot>) { [eventOrder addObject:@"listener1"]; });

auto listener2 = QueryListener::Create(query2, [eventOrder](const StatusOr<ViewSnapshot> &) {
[eventOrder addObject:@"listener2"];
});
auto listener2 = QueryListener::Create(
query2, [eventOrder](StatusOr<ViewSnapshot>) { [eventOrder addObject:@"listener2"]; });

auto listener3 = QueryListener::Create(query1, [eventOrder](const StatusOr<ViewSnapshot> &) {
[eventOrder addObject:@"listener3"];
});
auto listener3 = QueryListener::Create(
query1, [eventOrder](StatusOr<ViewSnapshot>) { [eventOrder addObject:@"listener3"]; });

FSTSyncEngine *syncEngineMock = OCMClassMock([FSTSyncEngine class]);
FSTEventManager *eventManager = [FSTEventManager eventManagerWithSyncEngine:syncEngineMock];
Expand Down
35 changes: 19 additions & 16 deletions Firestore/Example/Tests/Core/FSTQueryListenerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
#import "Firestore/Source/Core/FSTQuery.h"
#import "Firestore/Source/Core/FSTView.h"
#import "Firestore/Source/Model/FSTDocument.h"
#import "Firestore/Source/Util/FSTAsyncQueryListener.h"

#import "Firestore/Example/Tests/Util/FSTHelpers.h"

#include "Firestore/core/include/firebase/firestore/firestore_errors.h"
#include "Firestore/core/src/firebase/firestore/core/event_listener.h"
#include "Firestore/core/src/firebase/firestore/core/view_snapshot.h"
#include "Firestore/core/src/firebase/firestore/model/document_set.h"
#include "Firestore/core/src/firebase/firestore/model/types.h"
Expand All @@ -40,10 +40,12 @@
#include "Firestore/core/test/firebase/firestore/testutil/xcgmock.h"

using firebase::firestore::FirestoreErrorCode;
using firebase::firestore::core::AsyncEventListener;
using firebase::firestore::core::EventListener;
using firebase::firestore::core::DocumentViewChange;
using firebase::firestore::core::EventListener;
using firebase::firestore::core::ListenOptions;
using firebase::firestore::core::ViewSnapshot;
using firebase::firestore::core::ViewSnapshotHandler;
using firebase::firestore::model::DocumentKeySet;
using firebase::firestore::model::DocumentSet;
using firebase::firestore::model::OnlineState;
Expand Down Expand Up @@ -72,10 +74,11 @@ ViewSnapshot ExcludingMetadataChanges(const ViewSnapshot &snapshot) {
};
}

ViewSnapshotHandler Accumulating(std::vector<ViewSnapshot> *values) {
return [values](const StatusOr<ViewSnapshot> &maybe_snapshot) {
values->push_back(maybe_snapshot.ValueOrDie());
};
ViewSnapshot::Listener Accumulating(std::vector<ViewSnapshot> *values) {
return EventListener<ViewSnapshot>::Create(
[values](const StatusOr<ViewSnapshot> &maybe_snapshot) {
values->push_back(maybe_snapshot.ValueOrDie());
});
}

} // namespace
Expand Down Expand Up @@ -166,26 +169,26 @@ - (void)testRaisesEventForEmptyCollectionAfterSync {
}

- (void)testMutingAsyncListenerPreventsAllSubsequentEvents {
__block std::vector<ViewSnapshot> accum;
std::vector<ViewSnapshot> accum;

FSTQuery *query = FSTTestQuery("rooms/Eros");
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 3, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
FSTDocument *doc2 = FSTTestDoc("rooms/Eros", 4, @{@"name" : @"Eros2"}, FSTDocumentStateSynced);

__block FSTAsyncQueryListener *listener = [[FSTAsyncQueryListener alloc]
initWithExecutor:_executor.get()
snapshotHandler:^(const StatusOr<ViewSnapshot> &maybe_snapshot) {
accum.push_back(maybe_snapshot.ValueOrDie());
[listener mute];
}];
std::shared_ptr<AsyncEventListener<ViewSnapshot>> listener =
AsyncEventListener<ViewSnapshot>::Create(
_executor.get(), EventListener<ViewSnapshot>::Create(
[&accum, &listener](const StatusOr<ViewSnapshot> &maybe_snapshot) {
accum.push_back(maybe_snapshot.ValueOrDie());
listener->Mute();
}));

FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
ViewSnapshot viewSnapshot1 = FSTTestApplyChanges(view, @[ doc1 ], absl::nullopt).value();
ViewSnapshot viewSnapshot2 = FSTTestApplyChanges(view, @[ doc2 ], absl::nullopt).value();

ViewSnapshotHandler handler = listener.asyncSnapshotHandler;
handler(viewSnapshot1);
handler(viewSnapshot2);
listener->OnEvent(viewSnapshot1);
listener->OnEvent(viewSnapshot2);

// Drain queue
XCTestExpectation *expectation = [self expectationWithDescription:@"Queue drained"];
Expand Down
24 changes: 24 additions & 0 deletions Firestore/Example/Tests/Integration/API/FIRFirestoreSourceTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ - (void)testGetCollectionWhileOnlineWithDefaultSource {
]));
}

- (void)testGetDocumentError {
FIRDocumentReference *doc = [self.db documentWithPath:@"foo/__invalid__"];

XCTestExpectation *completed = [self expectationWithDescription:@"get completed"];
[doc getDocumentWithCompletion:^(FIRDocumentSnapshot *snapshot, NSError *error) {
XCTAssertNotNil(error);
[completed fulfill];
}];

[self awaitExpectations];
}

- (void)testGetCollectionError {
FIRCollectionReference *col = [self.db collectionWithPath:@"__invalid__"];

XCTestExpectation *completed = [self expectationWithDescription:@"get completed"];
[col getDocumentsWithCompletion:^(FIRQuerySnapshot *snapshot, NSError *error) {
XCTAssertNotNil(error);
[completed fulfill];
}];

[self awaitExpectations];
}

- (void)testGetDocumentWhileOfflineWithDefaultSource {
FIRDocumentReference *doc = [self documentRef];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ - (TargetId)addUserListenerWithQuery:(FSTQuery *)query {
// TODO(dimond): Allow customizing listen options in spec tests
// TODO(dimond): Change spec tests to verify isFromCache on snapshots
ListenOptions options = ListenOptions::FromIncludeMetadataChanges(true);
auto listener = std::make_shared<QueryListener>(
auto listener = QueryListener::Create(
query, options, [self, query](const StatusOr<ViewSnapshot> &maybe_snapshot) {
FSTQueryEvent *event = [[FSTQueryEvent alloc] init];
event.query = query;
Expand Down
31 changes: 21 additions & 10 deletions Firestore/Source/API/FIRDocumentReference.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "Firestore/core/src/firebase/firestore/api/document_reference.h"
#include "Firestore/core/src/firebase/firestore/api/document_snapshot.h"
#include "Firestore/core/src/firebase/firestore/core/event_listener.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
#include "Firestore/core/src/firebase/firestore/model/document_set.h"
#include "Firestore/core/src/firebase/firestore/model/precondition.h"
Expand All @@ -48,6 +49,7 @@
using firebase::firestore::api::DocumentReference;
using firebase::firestore::api::DocumentSnapshot;
using firebase::firestore::api::Firestore;
using firebase::firestore::core::EventListener;
using firebase::firestore::core::ListenOptions;
using firebase::firestore::core::ParsedSetData;
using firebase::firestore::core::ParsedUpdateData;
Expand Down Expand Up @@ -213,21 +215,30 @@ - (void)getDocumentWithSource:(FIRFirestoreSource)source
listener:(FIRDocumentSnapshotBlock)
listener {
ListenerRegistration result = _documentReference.AddSnapshotListener(
[self wrapDocumentSnapshotBlock:listener], std::move(internalOptions));
std::move(internalOptions), [self wrapDocumentSnapshotBlock:listener]);
return [[FSTListenerRegistration alloc] initWithRegistration:std::move(result)];
}

- (StatusOrCallback<DocumentSnapshot>)wrapDocumentSnapshotBlock:(FIRDocumentSnapshotBlock)block {
FIRFirestore *firestore = self.firestore;
return [block, firestore](StatusOr<DocumentSnapshot> maybe_snapshot) {
if (maybe_snapshot.ok()) {
FIRDocumentSnapshot *result =
[[FIRDocumentSnapshot alloc] initWithSnapshot:std::move(maybe_snapshot).ValueOrDie()];
block(result, nil);
} else {
block(nil, util::MakeNSError(maybe_snapshot.status()));
- (DocumentSnapshot::Listener)wrapDocumentSnapshotBlock:(FIRDocumentSnapshotBlock)block {
class Converter : public EventListener<DocumentSnapshot> {
public:
explicit Converter(FIRDocumentSnapshotBlock block) : block_(block) {
}

void OnEvent(StatusOr<DocumentSnapshot> maybe_snapshot) override {
if (maybe_snapshot.ok()) {
FIRDocumentSnapshot *result =
[[FIRDocumentSnapshot alloc] initWithSnapshot:std::move(maybe_snapshot).ValueOrDie()];
block_(result, nil);
} else {
block_(nil, util::MakeNSError(maybe_snapshot.status()));
}
}

private:
FIRDocumentSnapshotBlock block_;
};
return absl::make_unique<Converter>(block);
}

@end
Expand Down
52 changes: 26 additions & 26 deletions Firestore/Source/API/FIRQuery.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#import "Firestore/Source/Core/FSTQuery.h"
#import "Firestore/Source/Model/FSTDocument.h"
#import "Firestore/Source/Model/FSTFieldValue.h"
#import "Firestore/Source/Util/FSTAsyncQueryListener.h"
#import "Firestore/Source/Util/FSTUsageValidation.h"

#include "Firestore/core/src/firebase/firestore/model/document_key.h"
Expand All @@ -50,8 +49,9 @@
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"

namespace util = firebase::firestore::util;
using firebase::firestore::core::AsyncEventListener;
using firebase::firestore::core::EventListener;
using firebase::firestore::core::ViewSnapshot;
using firebase::firestore::core::ViewSnapshotHandler;
using firebase::firestore::model::DocumentKey;
using firebase::firestore::model::FieldPath;
using firebase::firestore::model::ResourcePath;
Expand Down Expand Up @@ -175,34 +175,34 @@ ListenOptions listenOptions(
Firestore *firestore = self.firestore.wrapped;
FSTQuery *query = self.query;

ViewSnapshotHandler snapshotHandler = [listener, firestore,
query](const StatusOr<ViewSnapshot> &maybe_snapshot) {
if (!maybe_snapshot.status().ok()) {
listener(nil, MakeNSError(maybe_snapshot.status()));
return;
}
ViewSnapshot snapshot = maybe_snapshot.ValueOrDie();
SnapshotMetadata metadata(snapshot.has_pending_writes(), snapshot.from_cache());

listener([[FIRQuerySnapshot alloc] initWithFirestore:firestore
originalQuery:query
snapshot:std::move(snapshot)
metadata:std::move(metadata)],
nil);
};
// Convert from ViewSnapshots to QuerySnapshots.
auto view_listener = EventListener<ViewSnapshot>::Create(
[listener, firestore, query](StatusOr<ViewSnapshot> maybe_snapshot) {
if (!maybe_snapshot.status().ok()) {
listener(nil, MakeNSError(maybe_snapshot.status()));
return;
}

ViewSnapshot snapshot = std::move(maybe_snapshot).ValueOrDie();
SnapshotMetadata metadata(snapshot.has_pending_writes(), snapshot.from_cache());

listener([[FIRQuerySnapshot alloc] initWithFirestore:firestore
originalQuery:query
snapshot:std::move(snapshot)
metadata:std::move(metadata)],
nil);
});

FSTAsyncQueryListener *asyncListener =
[[FSTAsyncQueryListener alloc] initWithExecutor:self.firestore.client.userExecutor
snapshotHandler:std::move(snapshotHandler)];
// Call the view_listener on the user Executor.
auto async_listener = AsyncEventListener<ViewSnapshot>::Create(firestore->client().userExecutor,
std::move(view_listener));

std::shared_ptr<QueryListener> internalListener =
[firestore->client() listenToQuery:query
options:internalOptions
viewSnapshotHandler:[asyncListener asyncSnapshotHandler]];
std::shared_ptr<QueryListener> query_listener =
[firestore->client() listenToQuery:query options:internalOptions listener:async_listener];

return [[FSTListenerRegistration alloc]
initWithRegistration:ListenerRegistration(firestore->client(), asyncListener,
std::move(internalListener))];
initWithRegistration:ListenerRegistration(firestore->client(), std::move(async_listener),
std::move(query_listener))];
}

- (FIRQuery *)queryWhereField:(NSString *)field isEqualTo:(id)value {
Expand Down
1 change: 0 additions & 1 deletion Firestore/Source/Core/FSTEventManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
namespace objc = firebase::firestore::util::objc;
using firebase::firestore::core::DocumentViewChange;
using firebase::firestore::core::ViewSnapshot;
using firebase::firestore::core::ViewSnapshotHandler;
using firebase::firestore::model::OnlineState;
using firebase::firestore::model::TargetId;
using firebase::firestore::util::MakeStatus;
Expand Down
8 changes: 4 additions & 4 deletions Firestore/Source/Core/FSTFirestoreClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@

NS_ASSUME_NONNULL_BEGIN

using firebase::firestore::api::DocumentSnapshot;
using firebase::firestore::core::ListenOptions;
using firebase::firestore::core::QueryListener;
using firebase::firestore::core::ViewSnapshot;

/**
* FirestoreClient is a top-level class that constructs and owns all of the pieces of the client
Expand Down Expand Up @@ -84,8 +86,7 @@ using firebase::firestore::core::QueryListener;
/** Starts listening to a query. */
- (std::shared_ptr<QueryListener>)listenToQuery:(FSTQuery *)query
options:(ListenOptions)options
viewSnapshotHandler:(firebase::firestore::core::ViewSnapshotHandler &&)
viewSnapshotHandler;
listener:(ViewSnapshot::SharedListener &&)listener;

/** Stops listening to a query previously listened to. */
- (void)removeListener:(const std::shared_ptr<QueryListener> &)listener;
Expand All @@ -95,8 +96,7 @@ using firebase::firestore::core::QueryListener;
* doesn't exist, an error will be sent to the completion.
*/
- (void)getDocumentFromLocalCache:(const firebase::firestore::api::DocumentReference &)doc
completion:(firebase::firestore::util::StatusOrCallback<
firebase::firestore::api::DocumentSnapshot> &&)completion;
completion:(DocumentSnapshot::Listener &&)completion;

/**
* Retrieves a (possibly empty) set of documents from the cache via the
Expand Down
19 changes: 9 additions & 10 deletions Firestore/Source/Core/FSTFirestoreClient.mm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
using firebase::firestore::auth::User;
using firebase::firestore::core::DatabaseInfo;
using firebase::firestore::core::ViewSnapshot;
using firebase::firestore::core::ViewSnapshotHandler;
using firebase::firestore::local::LruParams;
using firebase::firestore::model::DatabaseId;
using firebase::firestore::model::DocumentKeySet;
Expand Down Expand Up @@ -314,22 +313,22 @@ - (void)shutdownWithCompletion:(nullable FSTVoidErrorBlock)completion {

- (std::shared_ptr<QueryListener>)listenToQuery:(FSTQuery *)query
options:(ListenOptions)options
viewSnapshotHandler:(ViewSnapshotHandler &&)viewSnapshotHandler {
auto listener =
std::make_shared<QueryListener>(query, std::move(options), std::move(viewSnapshotHandler));
listener:(ViewSnapshot::SharedListener &&)listener {
auto query_listener = QueryListener::Create(query, std::move(options), std::move(listener));

_workerQueue->Enqueue([self, listener] { [self.eventManager addListener:listener]; });
_workerQueue->Enqueue([self, query_listener] { [self.eventManager addListener:query_listener]; });

return listener;
return query_listener;
}

- (void)removeListener:(const std::shared_ptr<QueryListener> &)listener {
_workerQueue->Enqueue([self, listener] { [self.eventManager removeListener:listener]; });
}

- (void)getDocumentFromLocalCache:(const DocumentReference &)doc
completion:(StatusOrCallback<DocumentSnapshot> &&)completion {
_workerQueue->Enqueue([self, doc, completion] {
completion:(DocumentSnapshot::Listener &&)completion {
auto shared_completion = absl::ShareUniquePtr(std::move(completion));
_workerQueue->Enqueue([self, doc, shared_completion] {
FSTMaybeDocument *maybeDoc = [self.localStore readDocument:doc.key()];
StatusOr<DocumentSnapshot> maybe_snapshot;

Expand All @@ -349,8 +348,8 @@ - (void)getDocumentFromLocalCache:(const DocumentReference &)doc
"FIRFirestoreSourceCache to attempt to retrieve the document "};
}

if (completion) {
self->_userExecutor->Execute([=] { completion(std::move(maybe_snapshot)); });
if (shared_completion) {
self->_userExecutor->Execute([=] { shared_completion->OnEvent(std::move(maybe_snapshot)); });
}
});
}
Expand Down
Loading