mirror of
https://github.com/callumio/suck.git
synced 2026-03-21 22:18:10 +00:00
feat: implement asynchronous channel support with tokio integration
This commit is contained in:
parent
56d0889b37
commit
863ca61215
13 changed files with 385 additions and 33 deletions
27
src/asynchronous/traits.rs
Normal file
27
src/asynchronous/traits.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
pub use crate::error::Error as ChannelError;
|
||||
|
||||
#[async_trait]
|
||||
pub trait AsyncChannelSender<T>: Send + Sync {
|
||||
async fn send(&self, msg: T) -> Result<(), ChannelError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait AsyncChannelReceiver<T>: Send + Sync {
|
||||
async fn recv(&self) -> Result<T, ChannelError>;
|
||||
}
|
||||
|
||||
pub trait AsyncChannelType {
|
||||
type Sender<T: Send + 'static>: AsyncChannelSender<T>;
|
||||
type Receiver<T: Send + 'static>: AsyncChannelReceiver<T>;
|
||||
|
||||
fn create_request_channel() -> (
|
||||
Self::Sender<crate::types::Request>,
|
||||
Self::Receiver<crate::types::Request>,
|
||||
);
|
||||
fn create_response_channel<T: Send + 'static>() -> (
|
||||
Self::Sender<crate::types::Response<T>>,
|
||||
Self::Receiver<crate::types::Response<T>>,
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue