crunch/examples/basic-setup/src/main.rs
kjuulh 7ff05b0ede
docs: update
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-09-24 22:04:34 +02:00

31 lines
692 B
Rust

mod gencrunch;
use gencrunch::basic::{includes::my_include::MyInclude, my_event::MyEvent};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let crunch = crunch::Builder::default().build()?;
crunch
.subscribe(|item: MyEvent| async move {
println!("received item: {:?}", item);
Ok(())
})
.await?;
crunch
.publish(MyEvent {
name: "some-name".into(),
include: Some(MyInclude {
name: "some-name".into(),
}),
})
.await?;
// Sleep a while to let subscriber catch item
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
Ok(())
}