summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2019-11-05 08:49:58 +0800
committerLi Haoyi <haoyi.sg@gmail.com>2019-11-05 08:49:58 +0800
commit35d3af1cd09d36c31744d214f0cadc3dd2ac51b2 (patch)
tree9c5a62ed0896d88f100b3c64e92bbae6335fa80e
parent3c7b7e70beb9013755bcaa0e724190bdfc8c99ea (diff)
downloadcask-35d3af1cd09d36c31744d214f0cadc3dd2ac51b2.tar.gz
cask-35d3af1cd09d36c31744d214f0cadc3dd2ac51b2.tar.bz2
cask-35d3af1cd09d36c31744d214f0cadc3dd2ac51b2.zip
0.3.40.3.4
-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