#[derive(Debug, PlexusWire)] pub enum CountEvent { Tick { n: u32 }, } #[derive(Clone, Default)] pub struct EchoActivation; /// Say things back. #[activation] impl EchoActivation { /// Ticks from 1 up to `to`. #[method] pub async fn count( &self, /// the last tick to: u32, ) -> impl Stream<Item = CountEvent> + Send + 'static { futures::stream::iter((1..=to).map(|n| CountEvent::Tick { n })) } }
Running `target/debug/myservice`
n: 1type: tickn: 2type: tickn: 3type: tick
echo v0.1.0 Say things back. USAGE synapse myservice echo <method> [flags] METHODS count Ticks from 1 up to `to`. schema Get plugin or method schema
{"content":{"n":1,"type":"tick"},"content_type":"echo.count","metadata":{"plexus_hash":"68e21310c712241b","provenance":["echo"],"timestamp":0},"type":"data"}{"content":{"n":2,"type":"tick"},"content_type":"echo.count","metadata":{"plexus_hash":"68e21310c712241b","provenance":["echo"],"timestamp":0},"type":"data"}{"metadata":{"plexus_hash":"68e21310c712241b","provenance":["echo"],"timestamp":0},"type":"done"}
==> Discovering tools...[+] Found all required tools==> Resolving myservice via registry at ws://127.0.0.1:4444...==> Reading schema...[+] Schema ready (2 plugins)==> Generating code...[+] Code generated (12 files)==> Installing dependencies...[+] Dependencies installed==> Building...[+] Build passed[+] Client → client/
export interface CountEventTick { type: 'tick'; n: number; } export type CountEvent = CountEventTick; export function isCountEventTick(e: CountEvent): e is CountEventTick { return e.type === 'tick'; }
/** Typed client interface for echo plugin */ export interface EchoClient { /** * Ticks from 1 up to `to`. * @requires `echo.count` anywhere it is held */ count(to: number): Promise<CountEvent>; /** * Get plugin or method schema. Pass {"method": "name"} for a specific method. * @requires `echo.schema` anywhere it is held */ schema(method?: string | null): Promise<SchemaResult>; }