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§
Sourcefn dispatch_req<'a>(
&'a self,
codec: &Arc<Self::Codec>,
req: RpcSvrReq<'a>,
noti: RespNoti<Self::RespTask>,
) -> impl Future<Output = Result<(), ()>> + Send
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.