I have following simple test code to try how to send messages between process.
The way I understand my code is :
- I spawn 2 separate processes
- Processes are executing functions where they should be awaiting a message
- In parent process I send a message to each process
- Processes should receive them and IO.puts message
What is happening is that nothing is in output and it looks as though program is executing but nothings happening. I have to cntrl+C out of it.
What am I doing wrong?
defmodule Test do
def startGame() do
hValue = 1
dValue = 2
parent = self()
hPID = spawn humanTurn(hValue, parent)
dPID = spawn dealerTurn(dValue, parent)
send(hPID, {:parent, dValue})
send(dPID, {:parent, dValue})
end
def dealerTurn(dValue, parent) do
receive do
{:parent, msg} -> IO.puts(msg)
end
end
def humanTurn(hValue, parent) do
receive do
{:parent, msg} -> IO.puts(msg)
end
end
end