Dispatch

Trait Dispatch 

Source
pub trait Dispatch:
    Send
    + Sync
    + Sized
    + Clone
    + 'static {
    type RespTask: ServerTaskResp;
    type Codec: Codec;

    // Required method
    fn dispatch_req<'a>(
        &'a self,
        codec: &Arc<Self::Codec>,
        req: RpcSvrReq<'a>,
        noti: RespNoti<Self::RespTask>,
    ) -> impl Future<Output = Result<(), ()>> + Send;
}
Expand description

Dispatch should be a user-defined struct initialized for every connection, by ServerFacts::new_dispatcher.

Dispatch must have Sync, because the connection reader and writer access concurrently.

A Codec should be created and holds inside, shared by the read/write coroutine. If you have encryption in the Codec, it could have shared states.

Required Associated Types§

Required Methods§

Source

fn dispatch_req<'a>( &'a self, codec: &Arc<Self::Codec>, req: RpcSvrReq<'a>, noti: RespNoti<Self::RespTask>, ) -> impl Future<Output = Result<(), ()>> + Send

Decode and handle the request, called from the connection reader coroutine.

You can dispatch them to a worker pool. If you are processing them directly in the connection coroutine, should make sure not blocking the thread for long. This is an async fn, but you should avoid waiting as much as possible. Should return Err(()) when codec decode_req failed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<C, T, R, H, F> Dispatch for DispatchClosure<C, T, R, H, F>
where C: Codec, T: ServerTaskDecode<R>, R: ServerTaskResp, H: FnOnce(T) -> F + Send + Sync + 'static + Clone, F: Future<Output = Result<(), ()>> + Send + 'static,