diff options
Diffstat (limited to 'src/actors/scala/actors/ReactorTask.scala')
-rw-r--r-- | src/actors/scala/actors/ReactorTask.scala | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/actors/scala/actors/ReactorTask.scala b/src/actors/scala/actors/ReactorTask.scala new file mode 100644 index 0000000000..7445097812 --- /dev/null +++ b/src/actors/scala/actors/ReactorTask.scala @@ -0,0 +1,64 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2005-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + +package scala.actors + +import java.lang.Runnable + +/** <p> + * The class <code>ReactorTask</code>... + * </p> + * + * @author Philipp Haller + */ +class ReactorTask extends Runnable { + + private var reactor: Reactor = null + private var fun: () => Unit = null + + def this(reactor: Reactor, block: => Unit) { + this() + this.reactor = reactor + this.fun = () => { block } + } + + def run() { + val saved = Actor.tl.get + Actor.tl set reactor + try { + try { + try { + fun() + } catch { + case e: Exception if (reactor.exceptionHandler.isDefinedAt(e)) => + reactor.exceptionHandler(e) + } + } catch { + case _: KillActorException => + } + reactor.kill() + } + catch { + case _: SuspendActorException => { + // do nothing (continuation is already saved) + } + case t: Exception => { + Debug.info(reactor+": caught "+t) + reactor.terminated() + } + } finally { + Actor.tl set saved + this.reactor = null + this.fun = null + } + } + +} |