Im creating a local library to my project that connects to a websocket server and generalizes some of the events.
The basic idea is connect, send message, read stream into buffer and the send data out via tokio::sync::watch. I'm finding that I'm either using channels or mutexs for handling the shared state. Is there a strategy that is less reliant on Arc<Mutex<T>> specifically?
Here's the growing mess
#[derive(Debug)]
pub struct Client {
connected: bool,
write: Option<SplitSink<SocketStream, Message>>,
/// By default this HeapAllocated Ring buffer will have a capacity of `1024`
/// This buffer will be used for data only
data_buffer: Arc<Mutex<VecDeque<(String, String)>>>,
/// This buffer will only be for non-data messages Eg: Hb, status, infor & warn messages
message_buffer: Arc<Mutex<VecDeque<String>>>,
/// Hold onto rx channels for consumers
subscriptions: BTreeMap<String, watch::Receiver<String>>,
/// Hold onto tx channels
senders: Arc<Mutex<BTreeMap<String, watch::Sender<String>>>>,
}