Skip to content

Answer to Exercise 5-7 of Chapter 6 - #29

Merged
axel22 merged 4 commits into
concurrent-programming-in-scala:masterfrom
ssmylh:ch6
Mar 25, 2016
Merged

Answer to Exercise 5-7 of Chapter 6#29
axel22 merged 4 commits into
concurrent-programming-in-scala:masterfrom
ssmylh:ch6

Conversation

@ssmylh

@ssmylh ssmylh commented Mar 19, 2016

Copy link
Copy Markdown
Contributor

@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
Copy Markdown
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

axel22 commented Mar 21, 2016

Copy link
Copy Markdown
Member

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

@ssmylh

ssmylh commented Mar 22, 2016

Copy link
Copy Markdown
Contributor Author

Thanks for your comment !
I will fix RMap.

- RMap.apply does not throw `NoSuchElementException'

- Fix memory leaks
@ssmylh

ssmylh commented Mar 24, 2016

Copy link
Copy Markdown
Contributor Author

@axel22 I fixed RMap.
Please review.

@axel22

axel22 commented Mar 25, 2016

Copy link
Copy Markdown
Member

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

ssmylh commented Mar 26, 2016

Copy link
Copy Markdown
Contributor Author

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