edwardyoon / heimdallr

Heimdallr, a Large-scale chat application server based on Redis Pubsub and Akka's actor model.
Apache License 2.0
54 stars 14 forks source link

Code refactoring #41

Open edwardyoon opened 5 years ago

edwardyoon commented 5 years ago

A member of Akka team provided great code review. We need to fix them at least.

https://github.com/akka/akka-http/issues/2391#issuecomment-459970316

lkaihua commented 5 years ago

Would really appreciate your efforts to keep open source code updated!

lkaihua commented 5 years ago

@jrudolph 's first suggestion is:

Try to get rid of mutable state as much as possible. Global mutable state in a singleton object (like ChatRooms) is absolutely forbidden ;)

In the latest version, the singleton ChatRoom still has a mutable variable to maintain the state:

var chatRooms: mutable.Map[Int, ActorRef]

It can be improved by using context.become:

context.become(update(chatRooms))

while update receives the current state as a parameter. (example)

edwardyoon commented 5 years ago

yeah, that's good point.