24 Jul 2013, 14:51
Dmfcb_pragsmall

David Copeland (98 posts)

In 14.2, there is an example of the client/server “tick/tock”, where the Ticker module has this as its start function:

def start do
  pid = spawn(__MODULE__, :generator, []) 
  :global.register_name(@name, pid)
end

Using this code, you get this when calling Tick.start:

=ERROR REPORT==== 24-Jul-2013::07:31:23 ===
Error in process <0.63.0> on node 'one@Davids-MacBook-Air' with exit value: {undef,[{'Elixir.Tick',generator,[],[]}]}

:yes

It seems that spawn requires its third argument to be a list of arguments, so in using an empty list, this is telling Elixir/Erlang to look for the function generator/0, because our list is empty. Since our function is generator/1, instead, pass it [[]] like so:

def start do
  pid = spawn(__MODULE__, :generator, [[]]) 
#                                     ^^^^ 
  :global.register_name(@name, pid)
end
  You must be logged in to comment