forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplyablereactor2.scala
55 lines (51 loc) · 1.05 KB
/
replyablereactor2.scala
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
import scala.actors._
import scala.actors.Actor._
class MyActor extends ReplyReactor {
def act() {
try {
loop {
react {
case 'hello =>
sender ! '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 Reactor[Any] {
def act() {
try {
react {
case r: MyActor =>
var i = 0
loop {
i += 1
val ft = r !! 'hello
val msg = ft()
if (i % 10000 == 0)
println(msg)
if (i >= 50000) {
r ! 'stop
exit()
}
}
}
} catch {
case e: Throwable if !e.isInstanceOf[scala.util.control.ControlThrowable] =>
e.printStackTrace()
}
}
}
b.start()
b ! a
}
}