summaryrefslogtreecommitdiff
path: root/test/files/jvm/actmig-react-within.scala
blob: 43350ef120854fdfb978c97978e04dec53dbdd1f (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
38
39
40
41
42
43
44
45
46
47
48
/**
 * NOTE: Code snippets from this test are included in the Actor Migration Guide. In case you change
 * code in these tests prior to the 2.10.0 release please send the notification to @vjovanov.
 */
import scala.actors.migration.MigrationSystem._
import scala.actors.Actor._
import scala.actors._
import scala.actors.migration._
import java.util.concurrent.{ TimeUnit, CountDownLatch }
import scala.collection.mutable.ArrayBuffer
import scala.concurrent.duration._
import scala.concurrent.{ Promise, Await }

object Test {
  val finished = Promise[Boolean]

  def testReactWithin() = {
    val sActor = actor {
      loop {
        reactWithin(1) {
          case scala.actors.TIMEOUT =>
            println("received")
            exit()
          case _ =>
            println("Should not occur.")
        }
      }
    }

    val myActor = MigrationSystem.actorOf(Props(() => new StashingActor {
      context.setReceiveTimeout(1 millisecond)
      def receive = {
        case ReceiveTimeout =>
          println("received")
          finished.success(true)
          context.stop(self)
        case _ =>
          println("Should not occur.")
      }
    }, "default-stashing-dispatcher"))
  }

  def main(args: Array[String]) = {
    testReactWithin()
    Await.ready(finished.future, 5 seconds)
  }

}