sausage-plugin part 2: import! with typed clients (sausage_interface::client_rs), TCP endpoints with rpc.endpoint, examples
Part 1 fixes: complete stdout writes, buffered stdin, Rust type names in schemas, enum variant docs, -32603 for serde errors in handlers, crate docs and modules. End-to-end check of a generated consumer through a fake core.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
//! 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 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)
|
||||
}
|
||||
Reference in New Issue
Block a user