blob: b94e804e63c498f3e4c4c738c1ebee6db5ae0de5 (
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
|
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()
}
}
}
object Test {
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
}
}
|