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

fix: dont poll stream again if done #2245

Merged
merged 1 commit into from Mar 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 18 additions & 14 deletions ethers-providers/src/stream/tx_stream.rs
Expand Up @@ -56,6 +56,8 @@ pub struct TransactionStream<'a, P, St> {
pub(crate) provider: &'a Provider<P>,
/// A stream of transaction hashes.
pub(crate) stream: St,
/// Marks if the stream is done
stream_done: bool,
/// max allowed futures to execute at once.
pub(crate) max_concurrent: usize,
}
Expand All @@ -68,6 +70,7 @@ impl<'a, P: JsonRpcClient, St> TransactionStream<'a, P, St> {
buffered: Default::default(),
provider,
stream,
stream_done: false,
max_concurrent,
}
}
Expand Down Expand Up @@ -102,21 +105,22 @@ where
}
}

let mut stream_done = false;
loop {
match Stream::poll_next(Pin::new(&mut this.stream), cx) {
Poll::Ready(Some(tx)) => {
if this.pending.len() < this.max_concurrent {
this.push_tx(tx);
} else {
this.buffered.push_back(tx);
if !this.stream_done {
loop {
match Stream::poll_next(Pin::new(&mut this.stream), cx) {
Poll::Ready(Some(tx)) => {
if this.pending.len() < this.max_concurrent {
this.push_tx(tx);
} else {
this.buffered.push_back(tx);
}
}
Poll::Ready(None) => {
this.stream_done = true;
break
}
_ => break,
}
Poll::Ready(None) => {
stream_done = true;
break
}
_ => break,
}
}

Expand All @@ -125,7 +129,7 @@ where
return tx
}

if stream_done && this.pending.is_empty() {
if this.stream_done && this.pending.is_empty() {
// all done
return Poll::Ready(None)
}
Expand Down