Comments (4)
I can think of multiple ways to solve this:
- Make an enum with all message types and implement
Handler
for that. - Have seperate list of
MessageChannel
s, one per message.MessageChannel
s are cheap to clone.
Do these Address
es point the same actor type or different ones?
from xtra.
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 Handler
s. 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.
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.
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)
- Way to mark time spent in queue and handler as follows_from request span HOT 4
- Have `Error::Disconnected` contain the actor name HOT 8
- Document features of `Context::stop_all` HOT 7
- Switch `WaitingSender` implementation to a oneshot channel implementation
- Re-organise cargo workspace
- Actor with a CPU-bound task HOT 8
- wait for actor to finish processing entire mailbox HOT 10
- Review changelog and sort by priority HOT 2
- `as_either` for `MessageChannel`? HOT 3
- See if we can simplify `TickFuture` HOT 4
- Switch to IntoFuture trait instead of modifying SendFuture
- wasm_bindgen::JsValue within Actor? HOT 4
- Feature Request: relax return type in into sink HOT 2
- Receiver<M> support HOT 7
- Context::notify_later replacement examples HOT 6
- Should we still recommend `spaad` in the README? HOT 3
- Experiment with nightly async fn in traits
- Atomicity of handlers HOT 2
- Actor persistence and journaling HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xtra.