1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-02 21:39:26 +00:00

Added comment.

This commit is contained in:
Yury Yarashevich 2023-10-19 11:24:14 +02:00
parent 7cc4210eb3
commit 7ecbefde38

View file

@ -333,9 +333,14 @@ impl CooperativeContentEncoder {
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<Option<Bytes>, EncoderError>> {
// The maximum computing budget can be utilized before yielding voluntarily
// See inspiration:
// https://tokio.rs/blog/2020-04-preemption
// https://ryhl.io/blog/async-what-is-blocking/
const BUDGET_LIMIT: u8 = 8;
let this = self.get_mut();
loop {
if this.budget_used > 8 {
if this.budget_used > BUDGET_LIMIT {
this.budget_used = 0;
cx.waker().wake_by_ref();
return Poll::Pending;