make transform DSL nicer, see #1966
This commit is contained in:
parent
838eaa4345
commit
c3f7aac8f3
4 changed files with 11 additions and 9 deletions
|
|
@ -268,7 +268,7 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" -> true)) with Im
|
|||
startWith(0, 0)
|
||||
when(0)(transform {
|
||||
case Event("go", _) ⇒ stay
|
||||
} {
|
||||
} using {
|
||||
case x ⇒ goto(1)
|
||||
})
|
||||
when(1) {
|
||||
|
|
|
|||
|
|
@ -217,8 +217,8 @@ trait FSM[S, D] extends Listeners with ActorLogging {
|
|||
* @param timeout state timeout for the initial state, overriding the default timeout for that state
|
||||
*/
|
||||
protected final def startWith(stateName: S,
|
||||
stateData: D,
|
||||
timeout: Timeout = None): Unit =
|
||||
stateData: D,
|
||||
timeout: Timeout = None): Unit =
|
||||
currentState = FSM.State(stateName, stateData, timeout)
|
||||
|
||||
/**
|
||||
|
|
@ -253,8 +253,12 @@ trait FSM[S, D] extends Listeners with ActorLogging {
|
|||
*/
|
||||
protected final def stop(reason: Reason, stateData: D): State = stay using stateData withStopReason (reason)
|
||||
|
||||
protected final def transform(func: StateFunction)(andThen: PartialFunction[State, State]): StateFunction =
|
||||
func andThen (andThen orElse { case x ⇒ x })
|
||||
protected final class TransformHelper(func: StateFunction) {
|
||||
def using(andThen: PartialFunction[State, State]): StateFunction =
|
||||
func andThen (andThen orElse { case x ⇒ x })
|
||||
}
|
||||
|
||||
protected final def transform(func: StateFunction): TransformHelper = new TransformHelper(func)
|
||||
|
||||
/**
|
||||
* Schedule named timer to deliver message after given delay, possibly repeating.
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ class FSMDocSpec extends AkkaSpec {
|
|||
when(SomeState)(transform {
|
||||
case Event(bytes: Array[Byte], read) ⇒ stay using (read + bytes.length)
|
||||
case Event(bytes: List[Byte], read) ⇒ stay using (read + bytes.size)
|
||||
} {
|
||||
} using {
|
||||
case s @ FSM.State(state, read, timeout, stopReason, replies) if read > 1000 ⇒
|
||||
goto(Processing)
|
||||
})
|
||||
|
|
@ -143,7 +143,7 @@ class FSMDocSpec extends AkkaSpec {
|
|||
when(SomeState)(transform {
|
||||
case Event(bytes: Array[Byte], read) ⇒ stay using (read + bytes.length)
|
||||
case Event(bytes: List[Byte], read) ⇒ stay using (read + bytes.size)
|
||||
}(processingTrigger))
|
||||
} using processingTrigger)
|
||||
//#alt-transform-syntax
|
||||
|
||||
//#termination-syntax
|
||||
|
|
|
|||
|
|
@ -329,8 +329,6 @@ be used several times, e.g. when applying the same transformation to several
|
|||
.. includecode:: code/akka/docs/actor/FSMDocSpec.scala
|
||||
:include: alt-transform-syntax
|
||||
|
||||
The parentheses are required by Scala’s syntax rules.
|
||||
|
||||
Timers
|
||||
------
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue