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

Help: notify_all not clear #106

Closed
overflowz opened this issue Jun 24, 2022 · 7 comments
Closed

Help: notify_all not clear #106

overflowz opened this issue Jun 24, 2022 · 7 comments

Comments

@overflowz
Copy link

Hey there! First of all, wanted to say thanks for this great library, tried many actor frameworks so far, but sticking with xtra due to its simplicity, speed, and easy handling of async/await :-)

I have a question about notify_all method, which is not clear to me. It says to notify the message to all of the actors running with the same address, but I wasn't able to figure out how to register two actors at the same address.

My goal is the following: I have some actor, which accepts messages, but also broadcasts (via notify_all) messages (like events). The only way I found to do this is to call clone_channel and pass it to the actor itself so the actor can call it later (vector of MessageChannel).

So there are two questions:

  1. What exactly is the use case of notify_all?
  2. How can I model xtra such it will notify all the actors that have handlers for the Message for example?

Thank you!

@thomaseizinger
Copy link
Collaborator

Thanks!

There are a lot of nice API changes coming in the next release that should make various use cases simpler. In particular, latest master already has a broadcast function on Address to send the same message to all actors.

You can run multiple actors on one Context by using Context::attach instead of Context::run. Note that that might also change until next release.

@overflowz
Copy link
Author

Thanks for the info! I'll be waiting for the next release then :-)

Keep it up!

@thomaseizinger
Copy link
Collaborator

thomaseizinger commented Jun 24, 2022

How can I model xtra such it will notify all the actors that have handlers for the Message for example?

If the recipients of your messages are different actors then the broadcast / notify_all function doesn't help you unfortunately. What you need is some sort of "fan-out" pattern where one actor holds a list of message channels and sending one message to that actor will send it to all.

You could also use AddressSink and use https://docs.rs/futures/latest/futures/sink/trait.SinkExt.html#method.fanout

@Restioson
Copy link
Owner

The relevant example is message_stealing.rs. It is probably worth adding some pointers somewhere around run so that Context::attach isn't missed!

@overflowz
Copy link
Author

Thank you for the replies, will definitely have a better look :)

@thomaseizinger
Copy link
Collaborator

Just as an FYI: We are hanging out in https://matrix.to/#/#xtra-community:matrix.org if you want to follow along more closely with the current development.

@overflowz
Copy link
Author

would've been joined if it were a discord, but I really don't use matrix (nor heard of it before). also, I don't think I'll be helpful that much, because I'm fairly new to rust:)

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

3 participants