Answer to Exercise 5-7 of Chapter 6 - #29
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.
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.