-
I'm trying to store an #[derive(Actor)]
pub struct SomeActor<A>
where
A: Actor + Message<SomeMessage>,
ActorRef<A>: Request<A, SomeMessage, A::Mailbox>,
{
other_actor: ActorRef<A>,
}
// Send SomeMessage like this later
self.other_actor.ask(SomeMessage).send().await; But I get this error when sending: The |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi rubengrim, this is perfect timing for something I've been working on today actually! I just saw this question are creating a PR with my rework of how sending is done. #39 With these new changes, all you should need are the following bounds for ask requests: Lines 166 to 169 in ad1984a In your case, since you're directly using SomeMessage , you would just need:
#[derive(Actor)]
pub struct SomeActor<A>
where
A: Actor<Mailbox = BoundedMailbox<A>> + Message<SomeMessage>,
{
other_actor: ActorRef<A>,
} However, this approach requires the mailbox to be known. If you want a super generic approach, you could do something like this: #[derive(Actor)]
struct SomeActor<A, Tm, Tr>
where
A: Actor + Message<SomeMessage>,
AskRequest<
LocalAskRequest<A, A::Mailbox>,
A::Mailbox,
SomeMessage,
Tm,
Tr,
>: MessageSend,
{
other_actor: ActorRef<A>,
}
actor_ref.ask(...).mailbox_timeout(...).reply_timeout(...).send().await If you know there will or will not be timeouts used here, you can hard code them to be An alternative to above with no timeouts available: #[derive(Actor)]
struct SomeActor<A>
where
A: Actor + Message<SomeMessage>,
AskRequest<
LocalAskRequest<A, A::Mailbox>,
A::Mailbox,
SomeMessage,
WithoutRequestTimeout,
WithoutRequestTimeout,
>: MessageSend,
{
other_actor: ActorRef<A>,
} It's quite verbose, but is pretty powerful for allowing different ways of sending messages based on mailbox type, or if there's timeouts used. |
Beta Was this translation helpful? Give feedback.
-
Just posting an update to this, with the PR #71, this issue should never come up anymore, as most request types work regardless of the actors mailbox. |
Beta Was this translation helpful? Give feedback.
Very cool of you to be looking into the source code :)
I have realised that your requirements aren't really dependant on the new PR I mentioned. I believe all you needed was to specify the mailbox there too.
A: Actor<Mailbox = BoundedMailbox<A>> + Message<SomeMessage>
The bounds required based on the current version of kameo are here:
kameo/src/request/ask.rs
Lines 374 to 389 in 6f7b6f7