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

Wait on correct Promise in subscription #29

Merged
merged 1 commit into from
Feb 2, 2017
Merged

Conversation

glasser
Copy link
Member

@glasser glasser commented Dec 22, 2016

I'm not a Promise expert, but the previous code at least read like it was
possible for the Promise returned by subscribe to resolve once all the
this.pubsub.subscribe Promises resolved but before all of the "push onto
this.subscriptions" Promises resolved. If unsubscribe was called too quickly,
you could in theory end up calling one of those "push" functions after the
delete this.subscriptions[subId] line and crashing.

In practice the old code does appear to work but this code more accurately shows
the intentions.

@benjamn this is the code I asked you for advice on, thanks!

I'm not a Promise expert, but the previous code at least read like it was
possible for the Promise returned by subscribe to resolve once all the
this.pubsub.subscribe Promises resolved but before all of the "push onto
this.subscriptions" Promises resolved.  If unsubscribe was called too quickly,
you could in theory end up calling one of those "push" functions after the
`delete this.subscriptions[subId]` line and crashing.

In practice the old code does appear to work but this code more accurately shows
the intentions.
@Urigo
Copy link
Contributor

Urigo commented Feb 2, 2017

Yeah that's makes sense!

@Urigo Urigo merged commit 9de160c into master Feb 2, 2017
@Urigo Urigo deleted the glasser/sub-promises branch February 2, 2017 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants