Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Why do we need Context/Address::stop_all #119

@thomaseizinger

Description

@thomaseizinger

With #118, Context::stop_all is moved to Address::stop_all.

Whilst doing this change and updating the docs, I was wondering why we need to provide this functionality within xtra? If the behaviour is the exact same as sending a Stop message to each actor, writing yourself a custom Address::stop_all function is pretty trivial:

struct Actor;
struct Stop;

#[async_trait]
impl Handler<Stop> for Actor {
    type Return = ();

    fn handle(&mut self, _: Stop, ctx: &mut Context<Self>) {
        ctx.stop();
    }
}

// To stop all actors:
address.broadcast(Stop).await;

If we still consider this too much boilerplate, we could provide a xtra-stop-handler crate that offers:

  • The Stop message type
  • A custom derive #[derive(StopHandler)]

Is there a reason why the implementation of stop_all needs to live xtra? There is a fair bit of code involved in providing it, like a custom envelope etc. We could save a good few lines of code by deleting it if it can really be expressed with existing building blocks.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions