代码之家  ›  专栏  ›  技术社区  ›  Willem

我怎么杀一个远程演员?

  •  4
  • Willem  · 技术社区  · 14 年前

    下面是一个演示问题的片段。

    import scala.actors._
    import scala.actors.remote._
    object TestMe {
      def main(args : Array[String]) : Unit = {
          object jim extends DaemonActor {
              // comment out these two lines and the application will terminate
              RemoteActor.alive(12345)
              RemoteActor.register('jim,this)         
              def act {
                  loop {
                      receive {
                          case 'quit =>
                           println("\nquiting")
                            exit('normal)
                          case any => 
                            println(any)
                      }
                  }
              }
          }
          jim.start
          jim ! "hello"
          jim ! 'quit
      }
    }
    
    1 回复  |  直到 14 年前
        1
  •  4
  •   Magnus    14 年前

    将.alive和.register调用放入act()中,代码将成功终止。