chore: preempt single block downloading (#11647)

This commit is contained in:
Matthias Seitz
2024-10-10 19:15:06 +02:00
committed by GitHub
parent fca1cd8181
commit 250785f833

View File

@ -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
}
}
}
}