Skip to content
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

Allow user to unlisten to queries after shutdown. #2083

Merged
merged 7 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion packages/firestore/src/core/firestore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ export class FirestoreClient {
}

unlisten(listener: QueryListener): void {
this.verifyNotShutdown();
this.asyncQueue.enqueueAndForget(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This potentially calls into the SyncEngine. I wonder if we should guard this on the shutdown state and not call unlisten if we are shut down?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

return this.eventMgr.unlisten(listener);
});
Expand Down
15 changes: 15 additions & 0 deletions packages/firestore/test/integration/api/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1120,4 +1120,19 @@ apiDescribe('Database', (persistence: boolean) => {
}).to.throw();
});
});

it('can unlisten queries after shutdown', async () => {
return withTestDoc(persistence, async docRef => {
const firestore = docRef.firestore;
const accumulator = new EventsAccumulator<firestore.DocumentSnapshot>();
const unsubscribe = docRef.onSnapshot(accumulator.storeEvent);
await accumulator.awaitEvent();
await shutdownDb(firestore);

// This should proceed without error.
unsubscribe();
// Multiple calls should proceed as well.
unsubscribe();
});
});
});