summaryrefslogtreecommitdiff
path: root/test/files/jvm/daemon-actor-termination.scala
blob: 7707ea8d4da8ddc4392d2f5a6fd8597882ac40bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import scala.actors.Actor
import scala.actors.scheduler.DefaultExecutorScheduler

/* Test that a daemon Actor that hasn't finished does not prevent termination */

trait DaemonActor extends Actor {
  override def scheduler =
    Test.daemonSched
}

object Test {
  val daemonSched =
    new DefaultExecutorScheduler(true)

  class MyDaemon extends DaemonActor {
    def act() {
      react {
        case 'hello =>
          println("MSG1")
          reply()
          react {
            case 'bye =>
              println("done")
          }
      }
    }
  }

  def main(args: Array[String]) {
    val daemon = new MyDaemon
    daemon.start()
    Actor.actor {
      daemon !? 'hello
      println("MSG2")
    }
  }
}