oldfartdeveloper (17) [Avatar] Offline
#1
In the first code block in section 6.2.8:

defmodule TodoServer do
  use GenServer

  def init(_) do
    :timer.send_interval(5000, :todo_cleanup)
    {:ok, nil}
  end
end


The problem is that you are completely diverting from the "other" requirement of the "init" method which is to initialize a TodoList.

Hence, shouldn't it be written as:

defmodule TodoServer do
  use GenServer

  def init(_) do
    :timer.send_interval(5000, :todo_cleanup)
    {:ok, TodoList.new}  # <==== HERE! remember what we were doing!
  end
end


Or, if you want to deviate from "the other" problem you're discussing, then change the name of the module altogether, i.e.

defmodule SomeServer do
  use GenServer

  def init(_) do
    :timer.send_interval(5000, :some_cleanup)
    {:ok, nil}
  end
end


This way, there is no ambiguity of what your intention is at this point in the book.

HTH,

Scott
sjuric (86) [Avatar] Offline
#2
Thank you for reporting. I caught this myself while doing some changes to chapter 6. Using a nil for the initial state doesn't make sense here. The changed version will be included in the next release.