-module(core_profile).
-export([start/0]).
start() ->
register(eProfile, spawn(loop())),
ok.
loop() ->
receive
{Key, Pid} -> Pid ! getKey();
{name, Pid} -> Pid ! getName();
{address, Pid} -> Pid ! getAddress()
end,
loop().
This is my code
when I try to start the loop from the shell i get stuck.
2> Pid = spawn(fun()-> a end).
<0.39.0>
3>c(core_profile.erl).
{ok, core_profile}
4>core_profile:start().
shouldn't the command return ok and then give me the next command line, instead of doing nothing?
When you do spawn(loop())
the loop
function is called to evaluate a result (which will be passed on to spawn
, so you enter the infinite loop.
Instead of calling the function you must pass the function reference by doing spawn(fun loop/0)
.