Skip to content

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

Merged
merged 4 commits into from
Mar 25, 2016

Conversation

ssmylh
Copy link
Contributor

@ssmylh ssmylh commented Mar 19, 2016

@axel22 Please review.

}

/* This method throws `NoSuchElementException` if the key does not exist in the map. */
def apply(k: K): Observable[V] = map.get(k).get
Copy link
Member

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.

@axel22
Copy link
Member

axel22 commented Mar 21, 2016

Thanks for the PR! Please see my comment about RMap.

@ssmylh
Copy link
Contributor Author

ssmylh commented Mar 22, 2016

Thanks for your comment !
I will fix RMap.

- RMap.apply does not throw `NoSuchElementException'

- Fix memory leaks
@ssmylh
Copy link
Contributor Author

ssmylh commented Mar 24, 2016

@axel22 I fixed RMap.
Please review.

@axel22
Copy link
Member

axel22 commented Mar 25, 2016

LGTM

Thanks a lot!

@axel22 axel22 merged commit 8d5f4aa into concurrent-programming-in-scala:master Mar 25, 2016
@ssmylh ssmylh deleted the ch6 branch March 25, 2016 23:59
@ssmylh
Copy link
Contributor Author

ssmylh commented Mar 26, 2016

I have learned a lot from you, thank you 😄

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.

2 participants