How to properly use akka actors in scala

后端 未结 2 1613
后悔当初
后悔当初 2021-01-16 19:33

I\'m relatively new to the idea of actors, and was wondering if I could get some critique on what I am doing. For part of a project, I need to have an actor that tells a col

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-16 20:06

    You can't remove state since TimeManager should contain list of actors.

    You could hide it:

    class TimeManager extends Actor {
      def receive = getBehavior(Nil)
      def getBehavior(actors: List[ActorRef]): Receive = {
        case AdvanceTime() => actors foreach (_ ! DateTime.now)
        case AddListener(x) => context become getBehavior(x :: actors)
      }
    }
    

提交回复
热议问题