Skip to main content

Crate cacp_events

Crate cacp_events 

Source
Expand description

A channel-based Client for cacp.

A frontend already has an event loop. channel hands it one instead of a trait to implement: a Client to give spawn, and the Events stream every call from the agent arrives on.

Anything you do not match on is declined with method not found, exactly as an unimplemented Client method would be — so a consumer that ignores an Event is indistinguishable on the wire from one that never served that method. Declare what you do serve in ClientCapabilities, as ever.

Notifications arrive in wire order. A request is dispatched on its own task, so it can reach the stream just after a notification that followed it on the wire.

use cacp_events::Event;

let (client, mut events) = cacp_events::channel();
let (_agent, _child) = cacp::spawn(&mut tokio::process::Command::new("my-agent"), client, None)?;

while let Some(event) = events.recv().await {
    match event {
        Event::Update(notification) => println!("{:?}", notification.update),
        Event::Permission(request, reply) => reply.send(
            cacp::schema::RequestPermissionResponse::selected(
                request.options[0].option_id.clone(),
            ),
        ),
        _ => {}
    }
}

Structs§

Channel
A Client that forwards its calls to an Events stream.
Reply
A request waiting on the consumer.

Enums§

Event
One inbound call from the agent.

Functions§

channel
A client to hand to spawn, and the stream its calls arrive on.

Type Aliases§

Events
Every call the agent makes, in one stream.