Skip to content

Commit

Permalink
0.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Nov 5, 2019
1 parent 3c7b7e7 commit 35d3af1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion cask/actor/src/Actors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
4 changes: 2 additions & 2 deletions docs/pages/4 - Cask Actors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 35d3af1

Please sign in to comment.