From 0d95261bbcd4429b115608e1afe6648b844d92dc Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Thu, 29 Nov 2007 18:51:31 +0000 Subject: Fixed issue that avoids evaluating expressions ... Fixed issue that avoids evaluating expressions after andThen and continue. --- src/actors/scala/actors/Actor.scala | 6 ++++-- src/actors/scala/actors/Reaction.scala | 32 +++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 9 deletions(-) (limited to 'src/actors') diff --git a/src/actors/scala/actors/Actor.scala b/src/actors/scala/actors/Actor.scala index beae0652a5..5bde8948ca 100644 --- a/src/actors/scala/actors/Actor.scala +++ b/src/actors/scala/actors/Actor.scala @@ -205,6 +205,7 @@ object Actor { */ def loopWhile(cond: => Boolean)(body: => Unit): Unit = if (cond) { body andThen loopWhile(cond)(body) } + else continue /** * Links self to actor to. @@ -261,7 +262,7 @@ object Actor { */ def exit(): Nothing = self.exit() - def continue: Unit = self.kill() + def continue: Unit = throw new KillActorException } /** @@ -612,7 +613,7 @@ trait Actor extends OutputChannel[Any] { private var isWaiting = false // guarded by lock of this - private def scheduleActor(f: PartialFunction[Any, Unit], msg: Any) = + protected def scheduleActor(f: PartialFunction[Any, Unit], msg: Any) = if ((f eq null) && (continuation eq null)) { // do nothing (timeout is handled instead) } @@ -697,6 +698,7 @@ trait Actor extends OutputChannel[Any] { throw new SuspendActorException } first + throw new KillActorException } private[actors] var links: List[Actor] = Nil diff --git a/src/actors/scala/actors/Reaction.scala b/src/actors/scala/actors/Reaction.scala index 1e8321e351..8807efa074 100644 --- a/src/actors/scala/actors/Reaction.scala +++ b/src/actors/scala/actors/Reaction.scala @@ -19,10 +19,24 @@ import java.lang.{InterruptedException, Runnable} * return type Nothing. *

* - * @version 0.9.8 + * @version 0.9.10 * @author Philipp Haller */ -private[actors] class ExitActorException extends Throwable +private[actors] class ExitActorException extends Throwable { + /* + * For efficiency reasons we do not fill in + * the execution stack trace. + */ + override def fillInStackTrace(): Throwable = this +} + +private[actors] class KillActorException extends Throwable { + /* + * For efficiency reasons we do not fill in + * the execution stack trace. + */ + override def fillInStackTrace(): Throwable = this +} /**

* The abstract class Reaction associates @@ -31,7 +45,7 @@ private[actors] class ExitActorException extends Throwable * java.lang.Runnable. *

* - * @version 0.9.8 + * @version 0.9.10 * @author Philipp Haller */ /*private[actors]*/ class Reaction(a: Actor, @@ -47,10 +61,14 @@ private[actors] class ExitActorException extends Throwable if (a.shouldExit) // links a.exit() else { - if (f == null) - a.act() - else - f(msg) + try { + if (f == null) + a.act() + else + f(msg) + } catch { + case _: KillActorException => + } a.kill(); a.exit() } } -- cgit v1.2.3