mirror of
https://github.com/actix/actix-web.git
synced 2025-01-05 14:58:44 +00:00
Added comment.
This commit is contained in:
parent
7cc4210eb3
commit
7ecbefde38
1 changed files with 6 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue