summaryrefslogtreecommitdiff
path: root/test/files/jvm/t3365.scala
blob: 83214280934b07b37557e8af87a3aa2606b5cc35 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@deprecated("Suppress warnings", since="2.11")
object Test {
import scala.actors.{ReplyReactor, Channel, Actor, Future}

case class ChannelMsg(chan: Channel[Any])

class MyActor extends Actor {
  def act() {
    try {
    val chan = new Channel[Any](this)
    loop {
      react {
        case other: ReplyReactor =>
          other ! ChannelMsg(chan)
          loop {
            chan.react {
              case 'hello =>
                reply('hello)
              case 'stop =>
                exit()
            }
          }
      }
    }
    } catch {
      case e: Throwable if !e.isInstanceOf[scala.util.control.ControlThrowable] =>
        e.printStackTrace()
    }
  }
}

  def main(args: Array[String]) {
    val a = new MyActor
    a.start()

    val b = new Actor {
      def act() {
        try {
        react {
          case ChannelMsg(c) =>
            var i = 0
            loop {
              i += 1
              val ft: Future[Any] = c !! 'hello
              ft.inputChannel.react {
                case msg =>
                  if (i % 10000 == 0)
                    println(msg)
                  if (i >= 50000) {
                    c ! 'stop
                    exit()
                  }
              }
            }
        }
        } catch {
          case e: Throwable if !e.isInstanceOf[scala.util.control.ControlThrowable] =>
            e.printStackTrace()
        }
      }
    }
    b.start()

    a ! b
  }
}