How to wait for Akka actor system to terminate?

前端 未结 7 697
温柔的废话
温柔的废话 2020-12-25 14:19

I need to start Akka (2.0) actor system, send in some messages, then wait for it to do heavy lifting. After that, I need to do something unrelated to those actors.

I

7条回答
  •  情歌与酒
    2020-12-25 15:19

    Just a side note for those running into this question for its title: Apparently, Akka 2.5 does not support actorSystem.awaitTermination anymore. Reason being why might be Akka's philosophy of avoiding any blocking calls. Instead, actorSystem.registerOnTermination(...) can be used as a non-blocking way to do actions while an ActorSystem is being shutdown.

    Nonetheless, you can still wait for your actor system to complete via a Future provided by ActorSystem.whenTerminated:

    val system = new ActorSystem("parallelRunners")
    val master = system.actorOf(Props[Master])
    master ! Start
    
    import scala.concurrent.Await
    import scala.concurrent.duration._
    Await.ready(system.whenTerminated, 365.days)
    

提交回复
热议问题