summaryrefslogtreecommitdiff
path: root/test/files/jvm/daemon-actor-termination.scala
blob: b089f652bffa64535a5a2d776e2ecc4794b6e3ad (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
import scala.actors.{Actor, 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")
    }
  }
}