This PR ensures the FSM actor replies to asks in the cats-actors way, i.e. by returning the responses directly to the caller of the ask instead of sending them as messages.
I tried to reconcile the original Akka implementation with the cats-actors style. The main issue is that classic Akka permits multiple responses for a single state change. These are accumulated in the State$replies list and sent as messages one by one on transition. More importantly, if you do not want any responses in a state change, you just leave that list empty by default.
In cats-actors, we only return a response once. For this reason, I opted to make the response type of the actor be a monoid. This covers all cases of not responding (yields Monoid$.empty), a single response, or multiple responses combined into 1.
The simplest way to handle this is to have the FSM actor response type be a list, but the user has the option of defining a custom response and its own Monoid.
We somewhat retain Akka's ability to respond by sending a message. We introduce a StateReplyType that controls how an FSM response is provided:
ReturnResponse: Return the value in order to fulfil an ask.
SendMessage: Send the response as a message to the original sender.
BothMessageAndResponse: Both send and return the response.
Notes:
The State$.replying method defaults to SendMessage.
Added a State$.returning method that responds using ReturnResponse.
Unlike Akka, we send a single message that combines all of the responses instead of a message for each response.
Breaking changes:
The FSM actor is no longer an Actor but a ReplyingActor so you need to use actorSystem.replyingActorOf (unless you typecast it to make the response type Any).
The response type of the FSM actor must be monoidal. Multiple responses are aggregated into one.
A more conscious decision must be made when constructing a replying state by choosing to use State$.replying or State$.returning.
See updated unit tests for examples. The README is also updated.
This PR ensures the FSM actor replies to asks in the cats-actors way, i.e. by returning the responses directly to the caller of the ask instead of sending them as messages.
I tried to reconcile the original Akka implementation with the cats-actors style. The main issue is that classic Akka permits multiple responses for a single state change. These are accumulated in the
State$replies
list and sent as messages one by one on transition. More importantly, if you do not want any responses in a state change, you just leave that list empty by default.In cats-actors, we only return a response once. For this reason, I opted to make the response type of the actor be a monoid. This covers all cases of not responding (yields
Monoid$.empty
), a single response, or multiple responses combined into 1.The simplest way to handle this is to have the FSM actor response type be a list, but the user has the option of defining a custom response and its own
Monoid
.We somewhat retain Akka's ability to respond by sending a message. We introduce a
StateReplyType
that controls how an FSM response is provided:ReturnResponse
: Return the value in order to fulfil an ask.SendMessage
: Send the response as a message to the original sender.BothMessageAndResponse
: Both send and return the response.Notes:
State$.replying
method defaults toSendMessage
.State$.returning
method that responds usingReturnResponse
.Breaking changes:
Actor
but aReplyingActor
so you need to useactorSystem.replyingActorOf
(unless you typecast it to make the response typeAny
).State$.replying
orState$.returning
.See updated unit tests for examples. The README is also updated.
requires suprnation/cats-actors#20 resolves suprnation/cats-actors#13