forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactor-receivewithin.scala
69 lines (66 loc) · 1.33 KB
/
actor-receivewithin.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import scala.actors.{Actor, TIMEOUT}
object A extends Actor {
def act() {
receive {
case 'done =>
var cnt = 0
while (cnt < 500) {
cnt += 1
receiveWithin (0) {
case 'msg =>
if (cnt % 100 == 0)
println("'msg")
case TIMEOUT =>
// should not happen
println("FAIL1")
}
}
cnt = 0
while (cnt < 500) {
cnt += 1
receiveWithin (0) {
case 'msg =>
// should not happen
println("FAIL2")
case TIMEOUT =>
if (cnt % 100 == 0)
println("TIMEOUT")
}
}
B ! 'next
receive { case 'done => }
cnt = 0
while (cnt < 501) {
cnt += 1
receiveWithin (500) {
case 'msg2 =>
if (cnt % 100 == 0)
println("'msg2")
case TIMEOUT =>
println("TIMEOUT")
}
}
}
}
}
object B extends Actor {
def act() {
A.start()
for (_ <- 1 to 500) {
A ! 'msg
}
A ! 'done
receive {
case 'next =>
for (_ <- 1 to 500) {
A ! 'msg2
}
A ! 'done
}
}
}
object Test {
def main(args:Array[String]) {
B.start()
}
}