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

Delete observer associated with a topic when cleanup function is called #60

Merged
merged 2 commits into from
Feb 28, 2018
Merged

Delete observer associated with a topic when cleanup function is called #60

merged 2 commits into from
Feb 28, 2018

Conversation

onlybakam
Copy link
Contributor

Multiple topics can be associated with a client. This happens when
multiple subscriptions are live on a single API. In that case,
clientTopics holds client => [topics]. When the cleanup function is
called, we should look for a topic within an existing list of topics
associated with the client to identify it. Doing this allows us to find
the correct <topic, client> pair which allows us to unsubsribe the
client from the topic and remove the observer tied to the topic. Leaving
a "completed" observer in topicObserver will lead to it being reused
if we cancel a subscription and then switch back to it. However since
the observer has been "completed", its next function would never be
called.

In unsubscribeFromTopic function, we should not delete a client key if the
list of subscribed topics is empty: the client has not been disconnected
yet. The client will be disconnected when disconnectAll is called the
next time request is invoked (next subscription setup).

Multiple topics can be associated with a client. This happens when
multiple subscriptions are live on a single API. In that case,
clientTopics holds client => [topics]. When the cleanup function is
called, we should look for a topic within an existing list of topics
associated with the client to identify it. Doing this allows us to find
the correct <topic, client> pair which allows us to unsubsribe the
client from the topic and remove the observer tied to the topic. Leaving
a "completed" observer in `topicObserver` will lead to it being reused
if we cancel a subscription and then switch back to it. However since
the observer has been "completed", its `next` function would never be
called.

In `unsubscribeFromTopic` function, we should not delete a `client` key if the
list of subscribed topics is empty: the client has not been disconnected
yet. The client will be disconnected when `disconnectAll` is called the
next time `request` is invoked (next subscription setup).
Copy link
Contributor

@manueliglesias manueliglesias left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Contributor

@elorzafe elorzafe left a comment

Choose a reason for hiding this comment

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

We need to double check this tomorrow

} else {
this.clientTopics.delete(client);
}
this.clientTopics.set(client, topics);
Copy link
Contributor

Choose a reason for hiding this comment

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

Pending: review what happen if client expires

} else {
this.clientTopics.delete(client);
}
this.clientTopics.set(client, topics);
Copy link
Contributor

Choose a reason for hiding this comment

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

Pending: review what happen if client expires

@manueliglesias manueliglesias added the bug Used as a label for bugs found in AppSync SDK label Feb 28, 2018
Copy link
Contributor

@elorzafe elorzafe left a comment

Choose a reason for hiding this comment

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

👍
Reviewed this morning

@manueliglesias manueliglesias merged commit 7ca4019 into awslabs:master Feb 28, 2018
@menkveldj
Copy link

thanks guys, this is huge! Will this be deployed to npm soon?

Thanks.

@manueliglesias
Copy link
Contributor

Hi @menkveldj

This is in npm now :)

@menkveldj
Copy link

menkveldj commented Mar 1, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used as a label for bugs found in AppSync SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants