You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@pragdave's Programming Elixir was the first Elixir book I read and I still use the Process Overhead demo with 1,000,000 processes to show off that new Elixir programmers shouldn't be worried about making Processes the way they would be with threads. Showing we can compile spawn/chain.ex and run it Chain.run(1_000_000) would be a good MVP target for us.
spawn/chain.ex
defmoduleChaindodefcounter(next_pid)doreceivedon->sendnext_pid,n+1endenddefcreate_processes(n)dolast=Enum.reduce1..n,self,fn(_,send_to)->spawn(Chain,:counter,[send_to])endsendlast,0# start the count by sending a zero to the last processreceivedo# and wait for the result to come back to usfinal_answerwhenis_integer(final_answer)->"Result is #{inspect(final_answer)}"endenddefrun(n)doIO.putsinspect:timer.tc(Chain,:create_processes,[n])endend
The book has the 1,000,000 processes run like this: elixir --erl "+P 1000000" -r chain.ex -e "Chain.run(1_000_000)".
Compiler
Anonymous functions
[h | t]
Multiple Erlang Modules
Runtime
receive
non-selective
selective
Status::Waiting (for when there is nothing to receive yet)
@pragdave's Programming Elixir was the first Elixir book I read and I still use the Process Overhead demo with 1,000,000 processes to show off that new Elixir programmers shouldn't be worried about making Processes the way they would be with threads. Showing we can compile
spawn/chain.ex
and run itChain.run(1_000_000)
would be a good MVP target for us.spawn/chain.ex
The book has the 1,000,000 processes run like this:
elixir --erl "+P 1000000" -r chain.ex -e "Chain.run(1_000_000)"
.[h | t]
receive
Status::Waiting
(for when there is nothing toreceive
yet)+/2
(+/2 #63 asadd_2
)<>/2
(used internally by Elixir interpolation)is_integer/1
(Partial Term and :erlang implementation #21)send/2
(:erlang.send/2 and !/2 infix operator #105)spawn/3
(:erlang.spawn/3 #118):timer.tc
(not a BIF, but uses these BIFs)apply/2
convert_time_unit/3
(convert_time_unit/3 #22)monotonic_time/0
(:erlang.monotonic_time/0 #107)IO.puts
(dependencies)Enum.reduce/3
(dependencies):lists.foldl/3
(dependencies)is_function/2
inspect/1
(dependencies)Inspect.Algebra
group/1
doc_group/2
to_doc/1
format/2
IO
iodata_to_binary/1
iolist_to_binary/1
The text was updated successfully, but these errors were encountered: