From edbd13249c38c5ebeee869ae324477753b5850da Mon Sep 17 00:00:00 2001 From: Manuel Thalmann <m@nuth.ch> Date: Thu, 10 Apr 2025 21:50:21 +0200 Subject: [PATCH] Limit flood if intervals in stream --- stream-composition/src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stream-composition/src/main.rs b/stream-composition/src/main.rs index 6b26149..cc3c3aa 100644 --- a/stream-composition/src/main.rs +++ b/stream-composition/src/main.rs @@ -5,9 +5,10 @@ fn main() { trpl::run(async { let messages = get_messages().timeout(Duration::from_millis(200)); let intervals = get_intervals() - .map(|count| format!("Interval: {count}")) + .map(|count| format!("Interval #{count}")) + .throttle(Duration::from_millis(100)) .timeout(Duration::from_secs(10)); - let merged = messages.merge(intervals); + let merged = messages.merge(intervals).take(20); let mut stream = pin!(merged); while let Some(result) = stream.next().await {