summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cask/actor/src/Actors.scala8
-rw-r--r--docs/pages/4 - Cask Actors.md4
2 files changed, 9 insertions, 3 deletions
diff --git a/cask/actor/src/Actors.scala b/cask/actor/src/Actors.scala
index 69a5289..84975ba 100644
--- a/cask/actor/src/Actors.scala
+++ b/cask/actor/src/Actors.scala
@@ -69,10 +69,16 @@ abstract class SimpleActor[T]()(implicit ac: Context) extends BaseActor[T]{
}
abstract class StateMachineActor[T]()(implicit ac: Context) extends SimpleActor[T]() {
- class State(val run: T => State)
+ class State(val run: T => State = null)
protected[this] def initialState: State
protected[this] var state: State = initialState
def run(msg: T): Unit = {
+ assert(state != null)
state = state.run(msg)
}
+}
+
+class ProxyActor[T, V](f: T => V, downstream: Actor[V])
+ (implicit ac: Context) extends SimpleActor[T]{
+ def run(msg: T): Unit = downstream.send(f(msg))
} \ No newline at end of file
diff --git a/docs/pages/4 - Cask Actors.md b/docs/pages/4 - Cask Actors.md
index 3e04834..e6be320 100644
--- a/docs/pages/4 - Cask Actors.md
+++ b/docs/pages/4 - Cask Actors.md
@@ -467,8 +467,8 @@ Note that while multiple threads can send messages to `Logger` at once, and the
`Flush()` message can also be sent at an arbitrary time in the future thanks to
the `ac.scheduleMsg` call, the actor will only ever process one message at a
time. This means you can be sure that it will transition through the two states
-`Idle` and `Buffering` in a straightforward manner, without worry about multiple
-threads executing at once and messing up the simple state machine.
+`Idle` and `Buffering` in a straightforward manner, without worrying about
+multiple threads executing at once and messing up the simple state machine.
## Debugging Actors