43 lines
1.4 KiB
Rust
43 lines
1.4 KiB
Rust
//! Consumer of the probe's actual discovered interface.
|
|
use sausage_plugin::{Result, rpc};
|
|
sausage_plugin::import!("probe");
|
|
struct Consumer;
|
|
#[rpc]
|
|
impl Consumer {
|
|
/// Route an imported call through the core.
|
|
async fn run(&self) -> Result<i32> {
|
|
Ok(probe::add(probe::Add { a: 2, b: 3 })
|
|
.detach()
|
|
.on_notify(|name, _| eprintln!("typed progress: {name}"))
|
|
.await? as i32)
|
|
}
|
|
/// Connect to a world endpoint from the real core.
|
|
async fn world_endpoint(&self) -> Result<u64> {
|
|
let control = probe::control::connect("/state/control").await?;
|
|
let received = std::rc::Rc::new(std::cell::Cell::new(false));
|
|
let progress = received.clone();
|
|
let result = control
|
|
.stats()
|
|
.on_notify(move |name, value| {
|
|
progress.set(name == "endpoint-progress" && value["value"] == 7);
|
|
})
|
|
.await?;
|
|
assert!(
|
|
received.get(),
|
|
"the endpoint must deliver progress before its result"
|
|
);
|
|
Ok(result)
|
|
}
|
|
/// Connect to the provider's endpoint and receive its notification.
|
|
async fn endpoint(&self) -> Result<u64> {
|
|
let control = probe::control::connect("/endpoint").await?;
|
|
control
|
|
.stats()
|
|
.on_notify(|name, _| eprintln!("endpoint notification: {name}"))
|
|
.await
|
|
}
|
|
}
|
|
fn main() {
|
|
sausage_plugin::run(Consumer)
|
|
}
|