-
Notifications
You must be signed in to change notification settings - Fork 6
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
Receiving data coming over relay #96
Conversation
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.
Good stuff! I marked some minor things.
lib/jerboa/client/worker.ex
Outdated
|
||
@spec update_subscriber_ref(subscribers, pid, reference) :: subscribers | ||
defp update_subscriber_ref(subscribers, sub_pid, sub_ref) do | ||
if Map.has_key?(subscribers, sub_pid) do |
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.
Map.has_key?
followed by Map.get
- we traverse the map twice, while Map.fetch
/Map.get_and_update
would do the job by traversing just once. Not a big deal (before we load test), but not complex to fix either.
lib/jerboa/client.ex
Outdated
Subscribes PID to data received from the given peer | ||
|
||
Message format is | ||
{:peer_data, client_pid :: pid,peer :: address, data :: binary} |
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.
pid,peer
-> pid, peer
lib/jerboa/client.ex
Outdated
Subscribes calling process to data received from the given peer | ||
|
||
Message format is | ||
{:peer_data, client_pid :: pid,peer :: address, data :: binary} |
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.
No space after comma, as above.
All green! |
This PR is an alternative implementation of #95.
Instead of installing handler functions in the client process, processes can subscribe to data sent by specified peers. This way we have even more generic behaviour plus we can easily track subscribers and clean up state related to them when they die.