remove andThen overload, #25133

This commit is contained in:
Patrik Nordwall 2018-05-23 16:35:23 +02:00
parent 51c9f8ee42
commit a30e039b04
4 changed files with 48 additions and 26 deletions

View file

@ -58,7 +58,7 @@ object Effect {
* Not for user extension.
*/
@DoNotInherit
trait Effect[+Event, State] extends akka.persistence.typed.javadsl.Effect[Event, State] { self: EffectImpl[Event, State]
trait Effect[+Event, State] { self: EffectImpl[Event, State]
/* All events that will be persisted in this effect */
def events: im.Seq[Event]
@ -68,10 +68,6 @@ trait Effect[+Event, State] extends akka.persistence.typed.javadsl.Effect[Event,
final def andThen(callback: State Unit): Effect[Event, State] =
CompositeEffect(this, SideEffect[Event, State](callback))
/** Convenience method to register a side effect with just a lazy expression */
final def andThen(callback: Unit): Effect[Event, State] =
CompositeEffect(this, SideEffect[Event, State]((_: State) callback))
/** The side effect is to stop the actor */
def andThenStop: Effect[Event, State] =
CompositeEffect(this, Effect.stop[Event, State])

View file

@ -64,7 +64,7 @@ object PerformanceSpec {
persistenceId = name,
"",
commandHandler = CommandHandler.command {
case StopMeasure Effect.none.andThen(probe.ref ! StopMeasure)
case StopMeasure Effect.none.andThen(_ probe.ref ! StopMeasure)
case FailAt(sequence) Effect.none.andThen(_ parameters.failAt = sequence)
case command other(command, parameters)
},
@ -80,7 +80,7 @@ object PerformanceSpec {
def eventSourcedTestPersistenceBehavior(name: String, probe: TestProbe[Command]) =
behavior(name, probe) {
case (CommandWithEvent(evt), parameters)
Effect.persist(evt).andThen({
Effect.persist(evt).andThen(_ {
parameters.persistCalls += 1
if (parameters.every(1000)) print(".")
if (parameters.shouldFail) throw TE("boom")

View file

@ -6,6 +6,7 @@ package akka.persistence.typed.scaladsl
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
import akka.actor.typed.{ ActorRef, Behavior }
import akka.actor.typed.scaladsl.Behaviors
import akka.actor.typed.scaladsl.ActorContext
@ -71,7 +72,7 @@ object PersistentActorCompileOnlyTest {
commandHandler = CommandHandler.command {
case Cmd(data, sender)
Effect.persist(Evt(data))
.andThen {
.andThen { _
sender ! Ack
}
},
@ -114,7 +115,7 @@ object PersistentActorCompileOnlyTest {
commandHandler = (ctx: ActorContext[Command], state, cmd) cmd match {
case DoSideEffect(data)
Effect.persist(IntentRecorded(state.nextCorrelationId, data)).andThen {
Effect.persist(IntentRecorded(state.nextCorrelationId, data)).andThen { _
performSideEffect(ctx.self, state.nextCorrelationId, data)
}
case AcknowledgeSideEffect(correlationId)
@ -223,7 +224,7 @@ object PersistentActorCompileOnlyTest {
commandHandler = (ctx, _, cmd) cmd match {
case RegisterTask(task)
Effect.persist(TaskRegistered(task))
.andThen {
.andThen { _
val child = ctx.spawn[Nothing](worker(task), task)
// This assumes *any* termination of the child may trigger a `TaskDone`:
ctx.watchWith(child, TaskDone(task))
@ -278,7 +279,7 @@ object PersistentActorCompileOnlyTest {
def addItem(id: Id, self: ActorRef[Command]) =
Effect
.persist[Event, List[Id]](ItemAdded(id))
.andThen(metadataRegistry ! GetMetaData(id, adapt))
.andThen(_ metadataRegistry ! GetMetaData(id, adapt))
PersistentBehaviors.receive[Command, Event, List[Id]](
persistenceId = "basket-1",
@ -348,7 +349,7 @@ object PersistentActorCompileOnlyTest {
Effect.none
case CheerUp(sender)
changeMoodIfNeeded(state, Happy)
.andThen {
.andThen { _
sender ! Ack
}
case Remember(memory)
@ -382,19 +383,44 @@ object PersistentActorCompileOnlyTest {
class State
private val commandHandler: CommandHandler[Command, Event, State] = CommandHandler.command {
case Enough
Effect.persist(Done)
.andThen((_: State) println("yay"))
.andThenStop
}
private val eventHandler: (State, Event) State = {
case (state, Done) state
}
PersistentBehaviors.receive[Command, Event, State](
persistenceId = "myPersistenceId",
emptyState = new State,
commandHandler = CommandHandler.command {
case Enough
Effect.persist(Done)
.andThen(println("yay"))
.andThenStop
commandHandler,
eventHandler)
}
object AndThenPatternMatch {
trait State
class First extends State
class Second extends State
PersistentBehaviors.receive[String, String, State](
persistenceId = "myPersistenceId",
emptyState = new First,
commandHandler = CommandHandler.command {
cmd
Effect.persist(cmd).andThen {
case _: First println("first")
case _: Second println("second")
}
},
eventHandler = {
case (state, Done) state
case (_: First, _) new Second
case (state, _) state
})
}
}

View file

@ -116,14 +116,14 @@ object PersistentBehaviorSpec {
case IncrementThenLogThenStop
Effect.persist(Incremented(1))
.andThen {
.andThen { (_: State)
loggingActor ! firstLogging
}
.andThenStop
case IncrementTwiceThenLogThenStop
Effect.persist(Incremented(1), Incremented(2))
.andThen {
.andThen { (_: State)
loggingActor ! firstLogging
}
.andThenStop
@ -160,30 +160,30 @@ object PersistentBehaviorSpec {
case IncrementTwiceAndThenLog
Effect
.persist(Incremented(1), Incremented(1))
.andThen {
.andThen { (_: State)
loggingActor ! firstLogging
}
.andThen {
.andThen { _
loggingActor ! secondLogging
}
case EmptyEventsListAndThenLog
Effect
.persist(List.empty) // send empty list of events
.andThen {
.andThen { _
loggingActor ! firstLogging
}
case DoNothingAndThenLog
Effect
.none
.andThen {
.andThen { _
loggingActor ! firstLogging
}
case LogThenStop
Effect.none
.andThen {
Effect.none[Event, State]
.andThen { _
loggingActor ! firstLogging
}
.andThenStop