use
{
thespis :: { * } ,
thespis_impl :: { * } ,
async_executors :: { AsyncStd } ,
std :: { error::Error } ,
tracing :: { * } ,
};
#[ derive( Actor ) ]
struct MyActor;
struct Ping;
impl Message for Ping
{
type Return = &'static str;
}
impl Handler< Ping > for MyActor
{
#[async_fn] fn handle( &mut self, _msg: Ping ) -> &'static str
{
info!( "Hi from MyActor" );
"pong"
}
}
#[async_std::main]
async fn main() -> Result< (), Box<dyn Error> >
{
tracing_subscriber::fmt::Subscriber::builder()
.with_env_filter( "trace,polling=warn,async_io=warn,async_std::warn" )
.init()
;
let mut addr = Addr::builder( "Alice" ).spawn( MyActor, &AsyncStd )?;
let mut addr2 = Addr::builder( "Bob" ).spawn( MyActor, &AsyncStd )?;
let result = addr .call( Ping ).await?;
let result2 = addr2.call( Ping ).await?;
assert_eq!( "pong", result );
assert_eq!( "pong", result2 );
dbg!( result );
dbg!( result2 );
Ok(())
}