pub trait ResourceUpdateHandler:
Send
+ Sync
+ Debug {
// Required method
fn handle_resource_update<'life0, 'async_trait>(
&'life0 self,
notification: ResourceUpdateNotification,
) -> Pin<Box<dyn Future<Output = HandlerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
Handler for resource update notifications
Resource update handlers receive notifications when resources that the client has subscribed to are modified. This enables reactive updates to cached data or UI refreshes when server-side resources change.
§Examples
use turbomcp_client::handlers::{ResourceUpdateHandler, ResourceUpdateNotification, HandlerResult};
use async_trait::async_trait;
#[derive(Debug)]
struct CacheInvalidationHandler;
#[async_trait]
impl ResourceUpdateHandler for CacheInvalidationHandler {
async fn handle_resource_update(
&self,
notification: ResourceUpdateNotification,
) -> HandlerResult<()> {
println!("Resource {} was {:?}",
notification.uri,
notification.change_type);
// In a real implementation, you might:
// - Invalidate cached data for this resource
// - Refresh UI components that display this resource
// - Log the change for audit purposes
// - Trigger dependent computations
Ok(())
}
}