fix: dont poll stream again if done (#2245)
This commit is contained in:
parent
ce26dfc0d6
commit
49dccf9d89
|
@ -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,
|
||||
}
|
||||
|
@ -68,6 +70,7 @@ impl<'a, P: JsonRpcClient, St> TransactionStream<'a, P, St> {
|
|||
buffered: Default::default(),
|
||||
provider,
|
||||
stream,
|
||||
stream_done: false,
|
||||
max_concurrent,
|
||||
}
|
||||
}
|
||||
|
@ -102,7 +105,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
let mut stream_done = false;
|
||||
if !this.stream_done {
|
||||
loop {
|
||||
match Stream::poll_next(Pin::new(&mut this.stream), cx) {
|
||||
Poll::Ready(Some(tx)) => {
|
||||
|
@ -113,19 +116,20 @@ where
|
|||
}
|
||||
}
|
||||
Poll::Ready(None) => {
|
||||
stream_done = true;
|
||||
this.stream_done = true;
|
||||
break
|
||||
}
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// poll running futures
|
||||
if let tx @ Poll::Ready(Some(_)) = this.pending.poll_next_unpin(cx) {
|
||||
return tx
|
||||
}
|
||||
|
||||
if stream_done && this.pending.is_empty() {
|
||||
if this.stream_done && this.pending.is_empty() {
|
||||
// all done
|
||||
return Poll::Ready(None)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue