use tracing::info;
use rogue_runtime::prelude::*;
rpc! {
struct Calculator {
id: InstanceId,
value: i64,
}
impl Identity for Calculator {
fn id(&self) -> &InstanceId {
&self.id
}
}
impl Calculator {
pub async fn new() -> Self {
Self {
id: InstanceId::new(),
value: 0,
}
}
pub async fn value(&self) -> i64 {
self.value
}
pub async fn add(&mut self, value: i64) {
self.value += value
}
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt()
.with_env_filter("calculator=info,runtime=trace")
.pretty()
.init();
info!("starting calculator example");
let runtime = Runtime::create("calculator".to_string()).await?;
runtime
.execute_local(async move {
let mut calc = Calculator::new().await;
calc.add(21).await;
calc.add(21).await;
let val = calc.value().await;
info!(id = %calc.id(), value = %val, "result");
Ok(())
})
.await?;
Ok(())
}