small medium large xlarge

24 Jul 2013, 14:51
David Copeland (511 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)

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,[],[]}]}


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)
You must be logged in to comment