Whenever you introduce an actor system and it lacks one function, feel free to add another actor to take care of this: in this case, create one actor whose job is to send graceful stop requests to your important actors and wait their completion. This actor can then turn off the acting system, and outside you are awaitTermination . If you created this actor using system.actorOf(Props[Terminator], "terminator") , you can close it with
system.actorFor("/user/terminator") ! MakeItStop // or whatever message you choose try system.awaitTermination(1.minute) // or however long it may take catch { case _: TimeoutException => system.shutdown() // as a last resort }
Roland Kuhn
source share