suprnation / cats-actors

Cats Actors framework for building apps which are reactive. Cats actors uses a conceptual actor model as a higher level abstraction for concurrency.
Apache License 2.0
105 stars 9 forks source link

fix: FSM actors to reply in cats-actors style #15

Closed PetrosPapapa closed 1 month ago

PetrosPapapa commented 3 months ago

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:

Notes:

Breaking changes:

See updated unit tests for examples. The README is also updated.

requires suprnation/cats-actors#20 resolves suprnation/cats-actors#13

PetrosPapapa commented 1 month ago

Updated the PR and description to reflect the latest changes after discussing the way forward with @cloudmark .

PetrosPapapa commented 1 month ago

Will be merged in #22