I'd like to send a message and get a String back.
How to launch future in Actix.
let my_response =
self.driver_address.send(GetDrvConfig {}).await.unwrap().unwrap();
and wait for a reply?
How to do it?
impl Handler<GetConfig> for DataHub
{
type Result = Result<String, ()>;
fn handle(&mut self, msg: GetConfig, _: &mut Self::Context)
-> Self::Result
{
let res =
self.driver_address.send(GetDrvConfig {}).await.unwrap().unwrap();
Ok(res)
}
}
#[derive(Debug, Clone)]
pub struct GetDrvConfig {}
impl Message for GetDrvConfig
{
type Result = Result<String, ()>;
}
impl Handler<GetDrvConfig> for Driver
{
type Result = Result<String, ()>;
fn handle(&mut self, _msg: GetDrvConfig, _: &mut Self::Context)
-> Self::Result
{
Ok("MY RESPONSE".to_string())
}
}
Edit:
let send_msg = drv_addr.send(GetDrvConfig {});
let send_to_other = actix::fut::wrap_future::<_, Self>(send_msg);
let _f = send_to_other.map(move |result, actor, _ctx| {
match result {
Ok(v) => {
// How to return a response?
let response = v.unwrap();
println!("RES: {}", response);
},
Err(_e) => {}
};
}).wait(ctx);