diff options
author | Philipp Haller <hallerp@gmail.com> | 2007-11-26 14:16:59 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2007-11-26 14:16:59 +0000 |
commit | e4d31aed1f5a15cd3da7e6ae4093160142625b77 (patch) | |
tree | 473bd4520692a4e47b9c70112654701c20b85046 /src/actors/scala/actors/Scheduler.scala | |
parent | 83ac2b566929edb17629d20bf4dcba3b8d2bd14e (diff) | |
download | scala-e4d31aed1f5a15cd3da7e6ae4093160142625b77.tar.gz scala-e4d31aed1f5a15cd3da7e6ae4093160142625b77.tar.bz2 scala-e4d31aed1f5a15cd3da7e6ae4093160142625b77.zip |
Fixed ticket #219.
Diffstat (limited to 'src/actors/scala/actors/Scheduler.scala')
-rw-r--r-- | src/actors/scala/actors/Scheduler.scala | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/actors/scala/actors/Scheduler.scala b/src/actors/scala/actors/Scheduler.scala index e92e76a803..ddf6df164b 100644 --- a/src/actors/scala/actors/Scheduler.scala +++ b/src/actors/scala/actors/Scheduler.scala @@ -22,7 +22,7 @@ import scala.collection.mutable.{ArrayBuffer, Buffer, HashMap, Queue, Stack, Has * The <code>Scheduler</code> object is used by * <code>Actor</code> to execute tasks of an execution of an actor. * - * @version 0.9.8 + * @version 0.9.10 * @author Philipp Haller */ object Scheduler { @@ -79,7 +79,22 @@ object Scheduler { def tick(a: Actor) = sched.tick(a) def terminated(a: Actor) = sched.terminated(a) def pendReaction: Unit = sched.pendReaction - def unPendReaction: Unit = sched.unPendReaction + + private val termHandlers = new HashMap[Actor, () => Unit] + def onTerminate(a: Actor)(f: => Unit) { + termHandlers += (a -> (() => f)) + } + + def unPendReaction(a: Actor) { + // execute registered termination handler (if any) + termHandlers.get(a) match { + case Some(handler) => handler() + case None => // do nothing + } + + // notify scheduler + sched.unPendReaction + } def shutdown() = sched.shutdown() |