Which is the best practice to initialize the state?

I’m using Phoenix to develop a poker game. I use a GenServer to handle the table state, which is initialized at the end of each game. Should I simply terminate the GenServer, let the Supervisor restart it, or use a function like handle_call(:reset, ...) to reset the state?

I would imagine you should initialize state at the start of each game using the init/1 callback. GenServer can then update state with each play. It can write updates to a database, or store the result after a game is over.

This might be useful and relevant: http://blog.tokafish.com/playing-poker-with-elixir-pt-2/

Thank you!

1 Like