use xtra::prelude::MessageChannel; /// A fan-out actor takes every incoming message and forwards it to a set of other actors. pub struct Actor> { receivers: Vec>>, } impl> Actor { pub fn new(receivers: &[&dyn MessageChannel]) -> Self { Self { receivers: receivers.iter().map(|c| c.clone_channel()).collect(), } } } impl xtra::Actor for Actor where M: xtra::Message {} #[async_trait::async_trait] impl xtra::Handler for Actor where M: xtra::Message + Clone + Sync + 'static, { async fn handle(&mut self, message: M, _: &mut xtra::Context) { for receiver in &self.receivers { // Not sure why here is no `do_send_async` ... let _ = receiver.do_send(message.clone()); } } }