All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scala.actors.Reaction.scala Maven / Gradle / Ivy

/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2005-2007, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id: Reaction.scala 10241 2007-03-08 10:06:20Z phaller $


package scala.actors

import java.lang.{InterruptedException, Runnable}

/** 

* This exception is thrown whenever an actor exits. * Its purpose is to let exit have * return type Nothing. *

* * @version 0.9.4 * @author Philipp Haller */ private[actors] class ExitActorException extends Throwable /** * The abstract class Reaction associates * an instance of an Actor with a * java.lang.Runnable. * * @version 0.9.4 * @author Philipp Haller */ private[actors] class Reaction(a: Actor, f: PartialFunction[Any, Unit], msg: Any) extends Runnable { def this(a: Actor) = this(a, null, null) def actor = a def run(): Unit = { val saved = Actor.tl.get.asInstanceOf[Actor] Actor.tl.set(a) Scheduler.unPendReaction a.isDetached = false try { try { if (a.shouldExit) // links a.exit() else { if (f == null) a.act() else f(msg) a.exit() } } catch { case _: ExitActorException => } } catch { case _: SuspendActorException => { // do nothing (continuation is already saved) } case t: Throwable => { // links if (!a.links.isEmpty) { a.exitLinked(t) } } } Actor.tl.set(saved) } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy