From c8b7f16b101b2281f31cb1744bbe15aefc44278c Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Wed, 8 Nov 2006 17:24:06 +0000 Subject: joins5.scala terminates automatically. --- docs/examples/actors/joins5.scala | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'docs') 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) } -- cgit v1.2.3