Skip to content

Add game state [dead]#4

Closed
kitallis wants to merge 10 commits intocljsfrom
game-state
Closed

Add game state [dead]#4
kitallis wants to merge 10 commits intocljsfrom
game-state

Conversation

@kitallis
Copy link
Copy Markdown
Contributor

  • Rename RoomChannel to GameChannel
  • Make the handlers room-sensitive

@kitallis kitallis marked this pull request as draft May 24, 2020 08:32
@yudistrange
Copy link
Copy Markdown
Contributor

These changes look alright

end

def add_host(name, host) do
GenServer.cast(ref(name), host)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using host I would make this an explicit tuple (like the one you are sending {:host, host})

That prevents calling this API with improper data. Currently I can potentially override the host variable to hit all the handle_cast callbacks. That should be restricted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

@kitallis kitallis marked this pull request as ready for review May 29, 2020 19:48

def start do
name = Nanoid.generate()
case Supervisor.supervise({Monitor, name: ref(name)}) do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR: Supervisor here shadows the Supervisor module. Maybe rename the alias to GameSupervisor or something else

%PencilSpaceServer.Game.State{host: 1}
"""
def update(name, %{"host" => host}) do
GenServer.call(ref(name), {:host, host})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This maybe a leaky abstraction. So now the Game module knows there is a GenServer running somewhere which handles this message. A more ideal approach would be to change this to Monitor.update(ref(name), {:host, host})

That way later on if you wish to move away from a GenServer to some other behaviour, the change would just be in the Monitor module.

So I would rather do it by moving this line to Monitor module and expose it as a function, which can then be called from Game module

Comment on lines +21 to +23
case Game.start do
{:ok, name} ->
Game.update(name, host)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If host is guaranteed to be present at the time of Game gen_server creation, maybe we can include this in the Monitor's init function instead.

Currently we are waiting to create a GenServer, and once it is created we are sending it a message again.

This is okay, but not optimal in the strictest sense.

Comment on lines +44 to +45
Game.update(name, Map.take(params, ["participant"]))
render_json(conn, :accepted, %{name: name})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Game.update will invoke a handle_call callback in `Monitor, which is sync. If sufficiently large number of people join the same group at the same time, the laggards will see high latency in http response. Maybe we can change the participant list update to be async by moving it to handle_cast.

This again is alright, I am just trying to highlight the scenarios in which the Pencil server may run into trouble.

@kitallis kitallis closed this May 31, 2020
@kitallis kitallis mentioned this pull request May 31, 2020
@kitallis kitallis changed the title Add game state Add game state [dead] May 31, 2020
@kitallis kitallis mentioned this pull request May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants