-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Agents without Output/callback #307
Comments
It should be optional for components using an agent to receive messages from it. Components which only |
Mostly ignoring the implementation suggestions of the OP, it might be better to attack this problem from the We currently have this: impl<T> Bridged for T where T: Agent {
fn bridge(callback: Callback<Self::Output>) -> Box<dyn Bridge<Self>> {
Self::Reach::spawn_or_join(callback)
}
}
pub trait Discoverer {
fn spawn_or_join<AGN: Agent>(_callback: Callback<AGN::Output>) -> Box<dyn Bridge<AGN>>{...}
}
pub trait Bridge<AGN: Agent> {
/// Send a message to an agent.
fn send(&mut self, msg: AGN::Input);
} What we wan't to see is: impl<T> Bridged for T where T: Agent {
fn bridge(callback: Callback<Self::Output>) -> Box<dyn Bridge<Self>> {
Self::Reach::spawn_or_join(callback)
}
fn bridge_with_no_response() -> Box<dyn Bridge<Self>> {
Self::Reach::spawn_or_join_without_callback()
}
}
pub trait Discoverer {
fn spawn_or_join<AGN: Agent>(_callback: Callback<AGN::Output>) -> Box<dyn Bridge<AGN>>{...}
fn spawn_or_join_without_callback<AGN: Agent>() -> Box<dyn Bridge<AGN>>{...}
}
// Bridge remains the same. The actual implementations of Lets drill down into the ContextBridge {
scope: self.scope.clone(),
id: id.into(),
} If this can be changed to be like: ContextBridge {
scope: self.scope.clone(),
id: Some(id.into()),
} With an optional fn create_no_callback_bridge(&self) -> ContextBridge<AGN> {
ContextBridge {
scope: self.scope.clone(),
id: None
}
} A bunch of associated code would have to change a little to handle the case where context bridges may not have an |
This change doesn't make sense for |
For the |
As @kellytk suggested in the gitter, |
Description
I'm submitting a Feature Request
For the Router I'm writing, I'm trying to make it as ergonomic as possible. One of the Issues I have, is that in some situations, I construct an Agent that will never have its callback called; I only want to send messages to it. Having to create a bridge using a callback that will never be called could be confusing to someone using the router.
I think this would best be dealt with by creating an analogue to Agent that doesn't have an
Output
associated type and can have a Bridge analogue constructed without a callback.This way, messages could be sent from a Component to an Agent-like struct which will send its own message to another Actor, without having to own the Agent. I would like a way to have
my_boxed_agent_bridge.send(MyMsg::Variant)
effectively instantiate theMyAgent
if it doesn't exist yet, and then call aMyAgent::handle(&mut self, MyMsg::Variant)
, which could then pass the message along.The text was updated successfully, but these errors were encountered: