heimdallr
heimdallr copied to clipboard
Code refactoring
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
Would really appreciate your efforts to keep open source code updated!
@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)
yeah, that's good point.