-
Notifications
You must be signed in to change notification settings - Fork 0
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
final submission #27
base: master
Are you sure you want to change the base?
final submission #27
Conversation
def counter(value \\ 0) do | ||
#state = %{:count => value } |
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.
-2 layout
Please try to indent things correctly
@@ -1,6 +1,24 @@ | |||
|
|||
defmodule Ex02 do | |||
|
|||
def new_counter(value) 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.
-10
This code contains a bug and a messy thing :)
The bug is that you use Agent.get followed by update. This introduces a race condition. It two processes access the counter at the same time, they could both receive the same value. Making the get_and_update atomic means that won't happen.
-4 idiom
new_counter
returns {:ok, pid}
, which means that next_value
has to deconstruct this to get the pid.
The :ok
part is really only used to make sure the agent was created. It should never leave new_counter
:
def new_counter(value) do
{ :ok, count } = Agent.start(fn -> value end)
count
end
@@ -60,7 +60,15 @@ defmodule Ex03 do | |||
""" | |||
|
|||
def pmap(collection, process_count, function) do | |||
« your code here » | |||
no_of_items = Enum.count(collection)/process_count |
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.
-2 layout
indentation, plus inconsistent use of spaces in parameter lists and around '='s.
-4 idiom
This is just crying out to be a pipeline.
Radhika Dharulkar
46911479