#![deny(missing_docs)]
use ghost_actor::*;
ghost_chan! {
pub chan HelloWorldApi<GhostError> {
fn hello_world() -> String;
}
}
#[tokio::main]
async fn main() -> Result<(), GhostError> {
let sender = spawn_hello_world().await?;
assert_eq!("hello world!", &sender.hello_world().await?);
println!("{}", sender.hello_world().await?);
Ok(())
}
pub async fn spawn_hello_world(
) -> Result<GhostSender<HelloWorldApi>, GhostError> {
let builder = actor_builder::GhostActorBuilder::new();
let sender = builder
.channel_factory()
.create_channel::<HelloWorldApi>()
.await?;
tokio::task::spawn(builder.spawn(HelloWorldImpl));
Ok(sender)
}
struct HelloWorldImpl;
impl GhostControlHandler for HelloWorldImpl {}
impl GhostHandler<HelloWorldApi> for HelloWorldImpl {}
impl HelloWorldApiHandler for HelloWorldImpl {
fn handle_hello_world(&mut self) -> HelloWorldApiHandlerResult<String> {
Ok(must_future::MustBoxFuture::new(async move {
Ok("hello world!".to_string())
}))
}
}