pub struct IPCClient { /* private fields */ }Expand description
A handle to a client connection.
This is the main entrypoint for making RPC calls, publishing events, or subscribing to topics. Internally it communicates with a background task (the “client actor”) that manages the network connection.
Implementations§
Source§impl IPCClient
impl IPCClient
Sourcepub async fn connect() -> Result<Self>
pub async fn connect() -> Result<Self>
Connect to the broker and spawn the client actor.
- If
BROKER_ADDRenvironment variable is set, it connects via TCP. - Otherwise it attempts local IPC:
- On Unix: connects to a Unix socket at
rpc::UNIX_PATH. - On Windows: connects to a named pipe at
rpc::PIPE_PATH.
- On Unix: connects to a Unix socket at
Returns a IPCClient that can be used to issue requests.
Sourcepub async fn remote_call<U, T>(
&self,
object: &str,
method: &str,
args: U,
) -> Result<T>
pub async fn remote_call<U, T>( &self, object: &str, method: &str, args: U, ) -> Result<T>
Call a method on a remote object.
object: name of the remote object.method: method name.args: JSON arguments.
Returns the deserialized RpcResponse or an error if
the call failed or connection was lost.
Sourcepub async fn publish(
&self,
object: &str,
topic: &str,
args: &Value,
) -> Result<()>
pub async fn publish( &self, object: &str, topic: &str, args: &Value, ) -> Result<()>
Publish an event to a remote object/topic.
Unlike [remote_call], this is fire-and-forget: no response is awaited.
Sourcepub async fn subscribe(
&self,
object: &str,
topic: &str,
) -> UnboundedReceiver<Value>
pub async fn subscribe( &self, object: &str, topic: &str, ) -> UnboundedReceiver<Value>
Subscribe to events from a remote object/topic.
Returns an mpsc::UnboundedReceiver where updates
will be delivered as serde_json::Value.
Sourcepub async fn subscribe_async<F>(&self, object: &str, topic: &str, callback: F)
pub async fn subscribe_async<F>(&self, object: &str, topic: &str, callback: F)
Subscribe asynchronously with a callback.
Spawns a background task that invokes callback whenever
a new event is received on the subscription.
Sourcepub async fn wait_for_object(&self, object: &str) -> Result<()>
pub async fn wait_for_object(&self, object: &str) -> Result<()>
Wait until a given object exists on the server.
This polls periodically using [has_object] until success.