mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: preempt single block downloading (#11647)
This commit is contained in:
@ -177,6 +177,9 @@ where
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let this = self.get_mut();
|
||||
|
||||
// preemptive yield point
|
||||
let mut budget = 4;
|
||||
|
||||
loop {
|
||||
match ready!(this.request.poll(cx)) {
|
||||
ResponseResult::Header(res) => {
|
||||
@ -232,6 +235,14 @@ where
|
||||
if let Some(res) = this.take_block() {
|
||||
return Poll::Ready(res)
|
||||
}
|
||||
|
||||
// ensure we still have enough budget for another iteration
|
||||
budget -= 1;
|
||||
if budget == 0 {
|
||||
// make sure we're woken up again
|
||||
cx.waker().wake_by_ref();
|
||||
return Poll::Pending
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user