Replies: 1 comment 2 replies
-
Hi @kunjee17
When all instances of an
The link and unlink methods let you run code when an actor is stopped/dies. Here's what that might look like: struct Counter { ... }
impl Actor for Counter {
async fn on_start(&mut self, actor_ref: ActorRef<Self>) -> Result<(), BoxError> {
self.addition.link_child(&actor_ref);
self.subtraction.link_child(&actor_ref);
}
async fn on_link_died(
&mut self,
actor_ref: WeakActorRef<Self>,
id: u64,
reason: ActorStopReason
) -> Result<Option<ActorStopReason>, BoxError> {
if id == self.addition.id() {
println!("addition actor died!");
} else if id == self.subtraction.id() {
println!("subtraction actor died!");
}
// We can't function without the child actors, so lets stop this actor
Ok(Some(ActorStopReason::Killed))
}
} So instead of using the |
Beta Was this translation helpful? Give feedback.
-
I have wrote a simple code to implement child actors. I am not sure I m going into a correct direction.
Here is the code and then I ll ask the question.
Now, when I stop the
counter_ref
does it stopaddition
andsubstraction
as well. Or do I have to do something else. Coming fromAkka
style of actor system I can't find anything that using actor to create child actors.I did find link and unlink child. But do I need to handle it in
addition
orsubtraction
. I am basically trying to use actor as unit of work. So, I need to create whole actor tree. May be before hand or some way dynamically on need to do basis. That what I m trying to achieve here. I am in right direction or do I need to change something?Beta Was this translation helpful? Give feedback.
All reactions