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

Conversation

wilhuff
Copy link
Contributor

@wilhuff wilhuff commented May 18, 2020

No description provided.

@google-oss-bot
Copy link

1 Warning
⚠️ Did you forget to add a changelog entry? (Add #no-changelog to the PR description to silence this warning.)

Generated by 🚫 Danger

Copy link

@thebrianchen thebrianchen left a comment

Choose a reason for hiding this comment

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

lgtm w/ question

@@ -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.

@thebrianchen thebrianchen assigned wilhuff and unassigned thebrianchen May 18, 2020
@wilhuff wilhuff force-pushed the wilhuff/async-queue-sis branch from 52e6801 to e496a14 Compare May 19, 2020 18:58
@wilhuff wilhuff merged commit d935e84 into master May 19, 2020
@wilhuff wilhuff deleted the wilhuff/async-queue-sis branch May 19, 2020 19:58
@firebase firebase locked and limited conversation to collaborators Jun 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants