small medium large xlarge

Generic-user-small
21 Jan 2018, 20:48
Yasser Fayad (1 post)

Hello Community,

I love the entire book content. Specially chapter 5, “Making the Functional Transition”; and that is where I faced the issue below.

I tried to use Counter V3 from the book shared code with the following calls: - {:ok, counter_pid} = CounterV3.start_link(0) - CounterV3.read(counter_pid)

Exception is:

** (EXIT from #PID<0.382.0>) evaluator process exited with reason: an exception was raised:
    ** (ArgumentError) argument error
        :erlang.send({#PID<0.382.0>, #Reference<0.573825780.2162163715.125329>}, {:counter, 0})
        (ex_lang) lib/making_fun_transition/counter_3.ex:35: CounterV3.loop/1

Interactive Elixir (1.5.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>
14:37:33.920 [error] Process #PID<0.384.0> raised an exception
** (ArgumentError) argument error
    :erlang.send({#PID<0.382.0>, #Reference<0.573825780.2162163715.125329>}, {:counter, 0})
    (ex_lang) lib/making_fun_transition/counter_3.ex:35: CounterV3.loop/1
28aa4bd_pragsmall
21 Jan 2018, 20:59
José Valim (62 posts)

Good catch. The loop function should be changed accordingly:

  def loop(counter) do
    receive do
      {:read, {caller, ref}} ->
        send(caller, {ref, counter})
        loop(counter)
      :bump ->
        loop(counter + 1)
    end
  end
You must be logged in to comment