From 769ba42f8566447a9cca1ee39fe783ae460ae906 Mon Sep 17 00:00:00 2001 From: gusto Date: Wed, 13 Nov 2024 04:55:13 +0200 Subject: [PATCH] Make cache optional (#51) --- simlib/netrunner/src/streaming/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/simlib/netrunner/src/streaming/mod.rs b/simlib/netrunner/src/streaming/mod.rs index fad48dc..249a53a 100644 --- a/simlib/netrunner/src/streaming/mod.rs +++ b/simlib/netrunner/src/streaming/mod.rs @@ -217,12 +217,14 @@ impl Default for StreamProducerInner { #[derive(Debug)] pub struct StreamProducer { inner: Arc>>, + with_cache: bool, } impl Default for StreamProducer { fn default() -> Self { Self { inner: Arc::new(Mutex::new(StreamProducerInner::default())), + with_cache: false, } } } @@ -231,6 +233,7 @@ impl Clone for StreamProducer { fn clone(&self) -> Self { Self { inner: Arc::clone(&self.inner), + with_cache: self.with_cache, } } } @@ -247,7 +250,7 @@ where { pub fn send(&self, record: R) -> anyhow::Result<()> { let mut inner = self.inner.lock().unwrap(); - if inner.senders.is_empty() { + if inner.senders.is_empty() && self.with_cache { inner.record_cache.push(Arc::new(record)); Ok(()) } else {