Git Product home page Git Product logo

Comments (4)

thomaseizinger avatar thomaseizinger commented on June 10, 2024

I can think of multiple ways to solve this:

  1. Make an enum with all message types and implement Handler for that.
  2. Have seperate list of MessageChannels, one per message. MessageChannels are cheap to clone.

Do these Addresses point the same actor type or different ones?

from xtra.

bobdebuildr avatar bobdebuildr commented on June 10, 2024

Thanks for your comments, that makes sense. I would have different actor types, in the example above e.g. DogActor and CatActor, both implementing the two Handlers. In my case, the types to be handled are already enums with lots of variants, so I think I would prefer option 2.

from xtra.

thomaseizinger avatar thomaseizinger commented on June 10, 2024

I have personally used (2) before and it worked well. You can also do something like this which cuts some of the boilerplate:

struct Channels {
    ch1: MessageChannel<Foo>,
    ch2: MessageChannel<Bar>
}

impl Channels {
    fn new<A: Handler<Foo> + Handler<Bar>>(addr: Address<A>) -> Self {
        Self {
            ch1: MessageChannel::new(addr.clone()),
            ch2: MessageChannel::new(addr)
        }
    }
}

That would avoid needing to pass the address to the same actor multiple times but allow for different actors serving as the backing one for the channels.

Hope this helps!

from xtra.

Restioson avatar Restioson commented on June 10, 2024

Overall, I'm not 100% sure if it's possible for xtra to provide some kind of combination message channel like this, unfortunately (how would this be expressible through the rust typesystem?). I think that the solution to the actual problems themselves have been discussed here though.

from xtra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.