feat: ✨ make SourceStream more reusable
This commit is contained in:
parent
ab8bd69ff4
commit
3393edfd90
@ -1,6 +1,7 @@
|
||||
use std::{fmt::Debug, pin::Pin};
|
||||
|
||||
use futures::Stream;
|
||||
use redis::stream::StreamMsg;
|
||||
|
||||
use {eyre::Result, tonic::async_trait};
|
||||
|
||||
@ -24,7 +25,7 @@ pub trait ToFromBusMessage {
|
||||
|
||||
/// 🐎 » supertrait combining all bus object traits + debug + send + sync + 'static
|
||||
pub trait BusMessage:
|
||||
ToBusVal + ToBusKey + ToFromBusMessage + Debug + Clone + Send + Sync + PartialEq + 'static
|
||||
ToBusVal + ToBusKey + ToFromBusMessage + Debug + PartialEq + StreamMsg + 'static
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -6,19 +6,20 @@ use {
|
||||
tokio::sync::broadcast::{self, Sender},
|
||||
};
|
||||
|
||||
use crate::bus::BusMessage;
|
||||
pub trait StreamMsg: Clone + Send + Sync + 'static {}
|
||||
|
||||
pub struct SourceStream<RM: BusMessage> {
|
||||
// TODO: move this to a separate module, or maybe to the lool library
|
||||
pub struct SourceStream<RM: StreamMsg> {
|
||||
sender: Option<Sender<RM>>,
|
||||
}
|
||||
|
||||
impl<RM: BusMessage> Default for SourceStream<RM> {
|
||||
impl<RM: StreamMsg> Default for SourceStream<RM> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<RM: BusMessage> SourceStream<RM> {
|
||||
impl<RM: StreamMsg> SourceStream<RM> {
|
||||
// Create a new SourceStream with a broadcast channel
|
||||
pub fn new() -> Self {
|
||||
let (sender, _) = broadcast::channel(100); // Adjust the buffer size as needed
|
||||
|
||||
@ -4,7 +4,7 @@ pub extern crate eyre;
|
||||
use {
|
||||
super::svc::RustlerMsg,
|
||||
crate::{
|
||||
bus::{BusMessage, ToBusKey, ToBusVal, ToFromBusMessage},
|
||||
bus::{redis::stream::StreamMsg, BusMessage, ToBusKey, ToBusVal, ToFromBusMessage},
|
||||
entities::{market, ticker},
|
||||
},
|
||||
async_trait::async_trait,
|
||||
@ -163,6 +163,7 @@ impl PartialEq<Quote> for Quote {
|
||||
}
|
||||
}
|
||||
|
||||
impl StreamMsg for Quote {}
|
||||
impl BusMessage for Quote {}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user