Skip to content

Make RemoveSnapshotsInSyncListener run on the async queue #5632

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 1 commit into from
May 19, 2020
Merged
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion Firestore/core/src/core/firestore_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,9 @@ void FirestoreClient::AddSnapshotsInSyncListener(

void FirestoreClient::RemoveSnapshotsInSyncListener(
const std::shared_ptr<EventListener<Empty>>& user_listener) {
event_manager_->RemoveSnapshotsInSyncListener(user_listener);
worker_queue_->Enqueue([this, user_listener] {
event_manager_->RemoveSnapshotsInSyncListener(user_listener);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question: Is the main reason that we don't std::move the listener pointer on remove because we no longer care about reference counts when it's about to be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving is only useful when the parameter is accepted by value (or by rvalue reference). This gives the caller's copy away.

In this case, RemoveSnapshotsInSyncListener takes a const reference to the user_listener so moving doesn't do anything, but it's not bumping the reference count anyway.

https://github.com/firebase/firebase-ios-sdk/blob/master/Firestore/core/src/core/event_manager.h#L68

To answer your follow-up question, RemoveSnapshotsInSyncListener takes the listener by const reference because it's not going to store the listener anyway. It's uses the reference passed to find associated data but forgets about it immediately. You only want to take something like that by value if your method will keep it. In that case std::move in the caller gives the caller's copy away.

});
}

} // namespace core
Expand Down