summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2006-11-08 17:24:06 +0000
committerPhilipp Haller <hallerp@gmail.com>2006-11-08 17:24:06 +0000
commitc8b7f16b101b2281f31cb1744bbe15aefc44278c (patch)
tree7f9a88086c3e8f104d3af982db23e11e65ba1f64 /docs
parentc3ff16d17e367e2d69646285a7a049b0f076d04e (diff)
downloadscala-c8b7f16b101b2281f31cb1744bbe15aefc44278c.tar.gz
scala-c8b7f16b101b2281f31cb1744bbe15aefc44278c.tar.bz2
scala-c8b7f16b101b2281f31cb1744bbe15aefc44278c.zip
joins5.scala terminates automatically.
Diffstat (limited to 'docs')
-rw-r--r--docs/examples/actors/joins5.scala12
1 files changed, 9 insertions, 3 deletions
diff --git a/docs/examples/actors/joins5.scala b/docs/examples/actors/joins5.scala
index fcf7d2390e..220ce2a131 100644
--- a/docs/examples/actors/joins5.scala
+++ b/docs/examples/actors/joins5.scala
@@ -24,7 +24,7 @@ abstract class Producer[T] {
def hasNext: boolean = lookAhead match {
case Some(x) => true
- case None => false
+ case None => { coordinator ! Stop; false }
}
def next: T = lookAhead match {
@@ -32,8 +32,12 @@ abstract class Producer[T] {
}
}
+ case object Stop
+ class StopException extends Throwable
+
/** A thread-based coordinator */
private val coordinator: Actor = actor {
+ try {
while (true) {
receive {
case Next =>
@@ -41,8 +45,10 @@ abstract class Producer[T] {
reply {
receive { case x: Option[_] => x }
}
+ case Stop => throw new StopException
}
}
+ } catch { case _: StopException => }
}
private val producer: Actor = actor {
@@ -65,7 +71,6 @@ object Test extends Application {
while (it.hasNext) {
Console.println(it.next)
}
- System.exit(0)
}
object Test2 extends Application {
@@ -109,6 +114,8 @@ object Test2 extends Application {
}
}
+ Debug.level = 3
+
// note that it works from the main thread
Console.print("PreOrder:")
for (val x <- new PreOrder(tree).iterator) Console.print(" "+x)
@@ -117,5 +124,4 @@ object Test2 extends Application {
Console.print("\nInOrder:")
for (val x <- new InOrder(tree).iterator) Console.print(" "+x)
Console.print("\n")
- System.exit(0)
}