-
Notifications
You must be signed in to change notification settings - Fork 105
Answer to Exercise 5-7 of Chapter 6 #29
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
Conversation
} | ||
|
||
/* This method throws `NoSuchElementException` if the key does not exist in the map. */ | ||
def apply(k: K): Observable[V] = map.get(k).get |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not throw an exception if there is no such element.
Instead, if there is a subscription, the reactive map should create an observable X such that when somebody subscribes to X, a key with the subject is added to the map if it does not already exist, and the observable subscribes to that subject. If the subscription is canceled (unsubscribe
), the subject is removed from the map, unless somebody stored an actual value to that key.
This way, map does not grow indefinitely (no memory leaks), and the semantics do not require that there is actually a key in the map - i.e. one component can subscribes to the key, and wait until the key appears.
Thanks for the PR! Please see my comment about |
Thanks for your comment ! |
- RMap.apply does not throw `NoSuchElementException' - Fix memory leaks
@axel22 I fixed |
LGTM Thanks a lot! |
I have learned a lot from you, thank you 😄 |
@axel22 Please review.