-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
coop: expose coop
as a public module
#7116
base: master
Are you sure you want to change the base?
Conversation
274caa1
to
59eca5d
Compare
Co-authored-by: Alice Ryhl <[email protected]>
#[doc(hidden)] | ||
#[deprecated = "Moved to tokio::task::coop::unconstrained"] | ||
pub use coop::unconstrained; | ||
#[doc(hidden)] | ||
#[deprecated = "Moved to tokio::task::coop::Unconstrained"] | ||
pub use coop::Unconstrained; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move these next to consume_budget
so they are grouped together?
/// Futures created by the tokio library functions are budget-aware and yield when there is no more | ||
/// budget left, but not all futures will be budget-aware. Consider future `A` that polls two inner | ||
/// futures `B` and `C`, and returns `Poll::Ready` when one of them is ready. If both inner futures | ||
/// were budget-aware, at some point the budget would be depleted which would cause both futures to | ||
/// return `Poll::Pending` resulting in `A` returning `Poll::Pending` as well. Yielding all the way | ||
/// back to the runtime, the budget would be reset, and `B` and `C` could make progress again. | ||
/// Now let's consider `B` is budget-aware, but `C` is not and is always ready. The budget will be | ||
/// depleted as before, but now since `C` always returns `Poll::Ready`, `A` will always return | ||
/// `Poll::Ready` as well. This way, `A` will not yield back to the runtime which will keep the budget | ||
/// depleted and `B` not making progress. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This explanation is confusing. And more generally, this seems like a niche use-case. Are there not more common use-cases for this that we can explain instead?
E.g. maybe just have this example:
if !has_budget_remaining() {
tokio::task::yield_now().await;
}
and say that this is similar to consume_budget
, but doesn't decrement the budget when non-zero.
This PR makes the
coop
module public and exposes thehas_budget_remaining
function.The motivation for this is to make
select!
budget-aware (see #7108). The exposed functionality is also useful when dealing with a combination of budget-aware and non-budget-aware futures.Related to #7111.