Trait Subscribable

Source
pub trait Subscribable:
    Send
    + Sync
    + 'static {
    // Required methods
    fn subscribe<M: ActonMessage + Send + Sync + 'static>(
        &self,
    ) -> impl Future<Output = ()> + Send + Sync + '_
       where Self: AgentHandleInterface + Subscriber;
    fn unsubscribe<M: ActonMessage>(&self)
       where Self: AgentHandleInterface + Subscriber;
}
Expand description

Enables an entity (typically an agent handle) to manage its subscriptions to message types via the system broker.

This trait provides methods to asynchronously subscribe and unsubscribe from specific message types (ActonMessage). Implementors, usually AgentHandle, interact with the central AgentBroker to register or deregister interest in receiving broadcast messages.

Required Methods§

Source

fn subscribe<M: ActonMessage + Send + Sync + 'static>( &self, ) -> impl Future<Output = ()> + Send + Sync + '_

Asynchronously subscribes the agent associated with this handle to messages of type M.

After subscribing, the agent will receive copies of messages of type M that are broadcast via the Broker trait.

§Type Parameters
  • M: The concrete message type to subscribe to. Must implement ActonMessage and be Send + Sync + 'static.
§Returns

A Future that completes once the subscription request has been sent to the broker. Completion does not guarantee the subscription is immediately active.

§Requirements

The implementing type Self must also implement AgentHandleInterface and Subscriber.

Source

fn unsubscribe<M: ActonMessage>(&self)

Sends a request to unsubscribe the agent associated with this handle from messages of type M.

After unsubscribing, the agent will no longer receive broadcast messages of type M.

Note: The default blanket implementation currently spawns a Tokio task to send the unsubscribe request asynchronously. The UnsubscribeBroker message itself might be incomplete in the current implementation (commented-out fields).

§Type Parameters
  • M: The concrete message type to unsubscribe from. Must implement ActonMessage.
§Requirements

The implementing type Self must also implement AgentHandleInterface and Subscriber.

Implementors§

Source§

impl<T> Subscribable for T
where T: AgentHandleInterface + Subscriber + Send + Sync + 'static,

Blanket implementation of Subscribable for types implementing necessary traits.

This implementation provides the subscribe and unsubscribe methods for any type T that implements AgentHandleInterface and Subscriber. It works by sending the appropriate internal messages ([SubscribeBroker] or [UnsubscribeBroker]) to the broker obtained via the Subscriber::get_broker method.