use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use boson::{configure, task, Boson, JsonExecutionContextFactory, MemQueueBackend};
static GREET_RUNS: AtomicUsize = AtomicUsize::new(0);
#[task(name = "greet")]
async fn greet(ctx: Box<dyn boson::ExecutionContext>, name: String) -> boson_core::Result<()> {
GREET_RUNS.fetch_add(1, Ordering::SeqCst);
println!("greet {} (actor={})", name, ctx.label());
Ok(())
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let (boson, manual) = Boson::builder()
.queue_backend(Arc::new(MemQueueBackend::new()))
.execution_context_factory(JsonExecutionContextFactory)
.auto_registry()
.without_worker()
.build_manual()?;
configure(boson.clone());
Greet::send_with(
serde_json::json!({"System": {"operation": "demo"}}),
GreetParams {
name: "world".into(),
},
)
.await?;
assert!(manual.try_run_next().await);
assert_eq!(GREET_RUNS.load(Ordering::SeqCst), 1);
Ok(())
}