| Crates.io | xtor |
| lib.rs | xtor |
| version | 0.9.10 |
| created_at | 2022-05-12 20:56:07.142381+00 |
| updated_at | 2022-05-30 07:36:47.305474+00 |
| description | Async Actor framework for Rust which is blazing fast and rock solid. |
| homepage | https://github.com/starcoinorg/xtor |
| repository | |
| max_upload_size | |
| id | 585476 |
| size | 110,935 |
Supervisor Broker Caller and so onadd xtor to your library
cargo add xtor
write some code
use anyhow::Result;
use async_trait::async_trait;
use xtor::actor::{context::Context, message::Handler, runner::Actor};
// first define actor
struct HelloActor;
impl Actor for HelloActor {}
// then define message
#[xtor::message(result = "()")]
#[derive(Debug)]
struct Hello;
// then impl the handler
#[async_trait]
impl Handler<Hello> for HelloActor {
async fn handle(&self, _ctx: &Context, msg: Hello) -> Result<()> {
println!("{:?} received", &msg);
Ok(())
}
}
// main will finish when all actors died out.
#[xtor::main]
async fn main() -> Result<()> {
let hello_actor = HelloActor;
let hello_actor_address = hello_actor.spawn().await?;
hello_actor_address.call::<HelloActor, Hello>(Hello).await
}
src/actor/* for pure async actor implementationsrc/utils/* for utilities both trait and default implementation such as
DefaultBrokerDefaultSupervisorService