pub struct WorkBudget { /* private fields */ }Expand description
Fuel shared by native workers while the store awaits their operation.
Admit work with charge; report already-performed work with record_fuel.
The caller settles the total once all workers have drained, even on failure.
Implementations§
Source§impl WorkBudget
impl WorkBudget
pub fn new(limit: u64) -> Self
Sourcepub fn with_cancellation(self, cancel: Arc<AtomicBool>) -> Self
pub fn with_cancellation(self, cancel: Arc<AtomicBool>) -> Self
Signal cooperative cancellation if reported work exceeds the limit.
Explicit admission failures return Exhausted directly instead.
pub fn charge(&self, rate: Rate, count: u64) -> Result<(), Exhausted>
pub fn charge_fuel(&self, amount: u64) -> Result<(), Exhausted>
Sourcepub fn record_fuel(&self, amount: u64)
pub fn record_fuel(&self, amount: u64)
Record work that has already happened. Keep its full cost even if it exceeds the limit; a worker’s next cancellation check can stop further work.
Sourcepub fn before_effect(&self)
pub fn before_effect(&self)
Call immediately before an external effect can begin. Later work counts without fuel refusal or fuel-driven cancellation. The operation owns this transition and must coordinate it with any concurrent admission checks. Existing cancellation (including a deadline) is never cleared.
pub fn spent(&self) -> u64
Sourcepub fn is_exhausted(&self) -> bool
pub fn is_exhausted(&self) -> bool
Whether reported work exceeded the limit before an effect began.