daily pastebin goal
53%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top