From 49eb4585d8001fabdd489a8ba112ac74482592a2 Mon Sep 17 00:00:00 2001 From: yuyang Date: Tue, 31 Oct 2023 13:36:32 +0800 Subject: [PATCH] receive data first --- sqlx-core/src/ext/async_stream.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sqlx-core/src/ext/async_stream.rs b/sqlx-core/src/ext/async_stream.rs index c08c0d9c74..a989cb6f3b 100644 --- a/sqlx-core/src/ext/async_stream.rs +++ b/sqlx-core/src/ext/async_stream.rs @@ -21,7 +21,7 @@ impl<'a, T> TryAsyncStream<'a, T> { Fut: 'a + Future> + Send, T: 'a + Send, { - let (mut sender, receiver) = mpsc::channel(0); + let (mut sender, receiver) = mpsc::channel(10); let future = f(sender.clone()); let future = async move { @@ -42,6 +42,12 @@ impl<'a, T> Stream for TryAsyncStream<'a, T> { type Item = Result; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + // fast path + let t = self.receiver.try_next(); + match t { + Ok(x) => return Poll::Ready(x), + Err(_) => {} + } let future = &mut self.future; pin_mut!(future);