Guest User

Untitled

a guest
Sep 14th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. Gracefully terminating a Scala program after using Actor.self
  2. object EchoActor extends DaemonActor {
  3. def act() {
  4. loop {
  5. react {
  6. case (x: Any, respondTo: Actor) => {
  7. println("echoActor Got message " + x)
  8. respondTo ! "Echoing: " + x
  9. }
  10. case msg => println("Can't handle message " + msg)
  11. }
  12. }
  13. }
  14. }
  15.  
  16. object TestRunner extends App {
  17. EchoActor.start()
  18. for (n <- 1 to 3) {
  19. EchoActor !("Time to echo", self)
  20. println(self.receiveWithin(1000) { case x => x})
  21. Actor.clearSelf() // <<-- This doesn't allow for graceful shutdown
  22. }
  23. Actor.resetProxy() // <<-- Neither does this
  24. println("Done.")
  25. }
  26.  
  27. scala.actorsScheduler.shutdown()
Add Comment
Please, Sign In to add comment