0

I'm using akka with PersistentFSM and would like to be able to reply to a message using the stateData value after the event has been applied

when(StartedState) {
    case Event(..., ...) =>
        ...
        stay applying BidPlaced(...) replying BidPlacedReply(stateData)
}

BidPlacedReply is an object with an apply method that allows to construct a BidPlacedReply based on some fields of my stateData, for example I would like to be able to reply with a BidPlacedReply containing the current highest bidder id, highest bidder price, ... and this values are computed in the applyEvent which modifies the state and produces the "stateAfter".

Unfortunatly the "replying BidPlacedReply(stateData)" method calls the BidPlacedReply.apply method with the stateData value before the applyEvent has been applied (that's what I see in my logs),

I have tried the following construct but it doesn't modifiy the stateData for the next message (need to call applying !!!)

applyEvent(BidPlaced(...), stateData) match {
    case stateDataAfter => stay replying BidPlacedReply(stateDataAfter)
}

Does anybody knowns how can I reply with the stateData value corresponding to the result of the applyEvent (the stateData "after") ?

user2971902
  • 63
  • 1
  • 4

1 Answers1

0

How about this?

when(StartedState) { case Event(..., ...) => ... stay applying BidPlaced(...) andThen { (stateDataAfter: ...) => sender() ! BidPlacedReply(stateDataAfter) } }