Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try receive data first when TryAsyncStream's poll_next. #2846

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion sqlx-core/src/ext/async_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<'a, T> TryAsyncStream<'a, T> {
Fut: 'a + Future<Output = Result<(), Error>> + 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 {
Expand All @@ -42,6 +42,12 @@ impl<'a, T> Stream for TryAsyncStream<'a, T> {
type Item = Result<T, Error>;

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
// 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);

Expand Down