feat: with subscription

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-09-23 22:38:12 +02:00
parent 05fb5c0722
commit 7b08b16cdb
10 changed files with 167 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{pin::Pin, sync::Arc};
use async_trait::async_trait;
@@ -6,7 +6,19 @@ use crate::{errors::TransportError, EventInfo};
#[async_trait]
pub trait Transport {
type Stream: futures::Stream<Item = Vec<u8>>;
async fn publish(&self, event_info: &EventInfo, content: Vec<u8>)
-> Result<(), TransportError>;
async fn subscriber(
&self,
event_info: &EventInfo,
) -> Result<Option<Self::Stream>, TransportError>;
}
pub type DynTransport = Arc<dyn Transport + Send + Sync + 'static>;
pub type DynTransport = Arc<
dyn Transport<Stream = Pin<Box<dyn futures::Stream<Item = Vec<u8>> + Send>>>
+ Send
+ Sync
+ 'static,
>;