[][src]Trait xi_rpc::Peer

pub trait Peer: Send + 'static {
    fn box_clone(&self) -> Box<dyn Peer>;
fn send_rpc_notification(&self, method: &str, params: &Value);
fn send_rpc_request_async(
        &self,
        method: &str,
        params: &Value,
        f: Box<dyn Callback>
    );
fn send_rpc_request(
        &self,
        method: &str,
        params: &Value
    ) -> Result<Value, Error>;
fn request_is_pending(&self) -> bool;
fn schedule_idle(&self, token: usize);
fn schedule_timer(&self, after: Instant, token: usize); }

The Peer trait represents the interface for the other side of the RPC channel. It is intended to be used behind a pointer, a trait object.

Required methods

fn box_clone(&self) -> Box<dyn Peer>

Used to implement clone in an object-safe way. For an explanation on this approach, see this thread.

fn send_rpc_notification(&self, method: &str, params: &Value)

Sends a notification (asynchronous RPC) to the peer.

fn send_rpc_request_async(
    &self,
    method: &str,
    params: &Value,
    f: Box<dyn Callback>
)

Sends a request asynchronously, and the supplied callback will be called when the response arrives.

Callback is an alias for FnOnce(Result<Value, Error>); it must be boxed because trait objects cannot use generic paramaters.

fn send_rpc_request(&self, method: &str, params: &Value) -> Result<Value, Error>

Sends a request (synchronous RPC) to the peer, and waits for the result.

fn request_is_pending(&self) -> bool

Determines whether an incoming request (or notification) is pending. This is intended to reduce latency for bulk operations done in the background.

fn schedule_idle(&self, token: usize)

Adds a token to the idle queue. When the runloop is idle and the queue is not empty, the handler's idle fn will be called with the earliest added token.

fn schedule_timer(&self, after: Instant, token: usize)

Like schedule_idle, with the guarantee that the handler's idle fn will not be called before the provided Instant.

Note

This is not intended as a high-fidelity timer. Regular RPC messages will always take priority over an idle task.

Loading content...

Implementors

impl Peer for DummyPeer[src]

impl<W: Write + Send + 'static> Peer for RawPeer<W>[src]

Loading content...