From 9507a20d8baa8e8932bb518ad2178100e1aad039 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Tue, 30 Jan 2024 12:27:49 +0100 Subject: [PATCH] Simplify stream implementation --- meilisearch/src/routes/logs.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/meilisearch/src/routes/logs.rs b/meilisearch/src/routes/logs.rs index 411eb3663..2bf4ecce7 100644 --- a/meilisearch/src/routes/logs.rs +++ b/meilisearch/src/routes/logs.rs @@ -99,6 +99,16 @@ impl futures_util::Stream for LogStreamer { } } +impl LogStreamer { + pub fn into_stream(self) -> impl futures_util::Stream> { + futures_util::stream::unfold(self, move |mut this| async move { + let vec = this.receiver.recv().await; + + vec.map(From::from).map(Ok).map(|a| (a, this)) + }) + } +} + pub fn make_layer< S: tracing::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span>, >( @@ -159,7 +169,7 @@ pub async fn get_logs( .unwrap(); if was_available { - Ok(HttpResponse::Ok().streaming(LogStreamer { receiver })) + Ok(HttpResponse::Ok().streaming(LogStreamer { receiver }.into_stream())) } else { Err(MeilisearchHttpError::AlreadyUsedLogRoute.into()) }