sdk: readable clients (no Empty wrapper, no unused error module), documented examples with tests
This commit is contained in:
@@ -28,6 +28,32 @@ impl Probe {
|
||||
async fn serve(&self) -> Result<()> {
|
||||
sausage_plugin::listen("/endpoint", std::rc::Rc::new(Control)).await
|
||||
}
|
||||
/// Forward detached progress through the real core.
|
||||
async fn relay(&self) -> Result<i32> {
|
||||
call("probe.progress", json!({}))
|
||||
.detach()
|
||||
.on_notify(move |name, params| {
|
||||
Ctx::default().notify(name, params).unwrap();
|
||||
})
|
||||
.await
|
||||
.map(|value| value.as_i64().unwrap() as i32)
|
||||
}
|
||||
/// Send progress before the final result.
|
||||
fn progress(&self, ctx: &Ctx) -> Result<i32> {
|
||||
ctx.notify("step", json!({"done":true}))?;
|
||||
Ok(42)
|
||||
}
|
||||
/// Start a detached service that survives this caller.
|
||||
async fn launch(&self) -> Result<String> {
|
||||
Ok(sausage_plugin::serde_json::from_value(
|
||||
call("probe.service", json!({})).detach().await?,
|
||||
)?)
|
||||
}
|
||||
/// Keep the process alive until the core closes stdin.
|
||||
async fn service(&self) -> Result<String> {
|
||||
sausage_plugin::listen("/state/control", std::rc::Rc::new(Control)).await?;
|
||||
Ok(sausage_plugin::pid())
|
||||
}
|
||||
/// Add two numbers.
|
||||
///
|
||||
/// The result is their sum.
|
||||
|
||||
Reference in New Issue
Block a user