Closed Mitrug closed 2 months ago
The problem is that actors reply differently in cats-actors than they do in Akka.
In Akka, an actor replies by sending the response via the mailbox. The ask pattern creates a temporary actor that receives the response and fulfills the promise of the ask
.
This is how the FSM is implemented as well, so that stayAndReply
in this example will send the reply/replies as a message. The receive
method calls processMsg
which returns F[Unit]
so it always responds with Unit
(which cannot be casted to List
here). As things stand, you cannot ask an FSM actor.
In contrast to Akka, the ReplyingActor
in cats-actors replies by returning the response in its ReplyingReceive
method. This response then completes a Deferred
, passing on the response directly and not through the mailbox.
In order to fix this, the FSM must ~create a ReplyingActor
and~ issue the response via the ReplyingReceive
method and not send it as a message.
In contrast to Akka, the ReplyingActor in cats-actors replies by returning the response in its ReplyingReceive method. This response then completes a Deferred, passing on the response directly and not through the mailbox.
Interesting -- I hadn't noticed this nuance before. So is the implication that ask
suspends the requesting Actor's current effect (and blocks its mailbox) until the response comes back?
Yes. Although you can start and get a fiber back and processing continues. You could join afterwards with the fiber when you actually need a reply.
Description
Calling 'ask' (?) on a ReplyingActor created by an FSM returns the following error. In my case the FSM returns a List[Int]:
Steps to Reproduce