Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys_recv not called on Actor #173

Open
milgner opened this issue Nov 9, 2021 · 0 comments
Open

sys_recv not called on Actor #173

milgner opened this issue Nov 9, 2021 · 0 comments

Comments

@milgner
Copy link

milgner commented Nov 9, 2021

Scenario: my actor registers a schedule and I was under the impression that I should cancel the schedule when the actor is shutting down. Unfortunately, Actor::post_stop doesn't have a reference to ActorSystem so I cannot cancel the schedule there.

It's possible that schedules for terminated actors get cleaned up automatically but during experimentation I realised that Actor::sys_recv doesn't get invoked even though the documentation suggests that it would be.

The following code only prints "Stopping the actor..." but not "System message!".

impl Actor for MyActor {
    type Msg = MyActorMsg;

    fn post_stop(&mut self) {
        println!("Stopping the actor for {}", self.configuration.uri);
        match self.schedule_id {
            Some(schedule_id) => {
                // TODO: how to cancel the schedule w/o reference to the ActorSystem?
                // ctx.system.cancel_schedule(schedule_id);
            }
            None => {
                warn!("Stopping the actor without any schedule running");
            }
        }
    }

    fn sys_recv(&mut self, ctx: &Context<Self::Msg>, msg: SystemMsg, sender: Sender) {
        println!("System message!");
    }

    fn recv(&mut self, ctx: &Context<Self::Msg>, msg: Self::Msg, sender: Sender) {
        self.receive(ctx, msg, sender)
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant