pub struct DynamicBudgetKey { /* private fields */ }Expand description
One registered dynamic key under a budget tree.
Cloning shares the same registration and generation. Every clone observes the same closed state, and only the last generation that holds a name can release it.
Implementations§
Source§impl DynamicBudgetKey
impl DynamicBudgetKey
Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
Returns the unique generation of this registration.
Sourcepub fn budget(&self) -> ResourceBudget
pub fn budget(&self) -> ResourceBudget
Returns the budget this key owns.
The key is the admission boundary for a dynamic key: work that has to be
waited for by Self::retire_until must be admitted through
Self::try_acquire or against this budget, because retirement waits
for the reservations on this node.
Sourcepub fn try_acquire(
&self,
bytes: usize,
class: BudgetClass,
) -> Result<ResourcePermit, DynamicKeyAdmissionRejection>
pub fn try_acquire( &self, bytes: usize, class: BudgetClass, ) -> Result<ResourcePermit, DynamicKeyAdmissionRejection>
Acquires capacity from this key.
§Errors
Returns DynamicKeyAdmissionRejection::Closed once the key is
retiring, or the budget rejection when the key’s budget is full.
Sourcepub async fn retire_until(&self, deadline: Instant) -> DynamicKeyRetirement
pub async fn retire_until(&self, deadline: Instant) -> DynamicKeyRetirement
Closes admission and waits for the reservations on this key to drain.
Retirement completes only when the node holds no reservations, which is
what makes it safe for the caller to stop accounting for this key. When
deadline elapses first, the registration stays held and the returned
DynamicKeyRetirement reports the real remaining work.