Struct budget_executor::asynchronous::singlethreaded::Context
source · [−]pub struct Context<Budget>(_)
where
Budget: Budgetable;
Expand description
A budget-limited asynchronous context.
Implementations
sourceimpl<Budget> Context<Budget> where
Budget: Budgetable,
impl<Budget> Context<Budget> where
Budget: Budgetable,
sourcepub fn run_with_budget<F>(
future: impl FnOnce(Context<Budget>) -> F,
initial_budget: Budget
) -> BudgetedFuture<Budget, F>ⓘNotable traits for BudgetedFuture<Budget, F>impl<Budget, F> Future for BudgetedFuture<Budget, F> where
Budget: Budgetable,
F: Future, type Output = Progress<Budget, F>;
where
F: Future,
pub fn run_with_budget<F>(
future: impl FnOnce(Context<Budget>) -> F,
initial_budget: Budget
) -> BudgetedFuture<Budget, F>ⓘNotable traits for BudgetedFuture<Budget, F>impl<Budget, F> Future for BudgetedFuture<Budget, F> where
Budget: Budgetable,
F: Future, type Output = Progress<Budget, F>;
where
F: Future,
Budget: Budgetable,
F: Future, type Output = Progress<Budget, F>;
Executes future
with the provided budget. The future will run until it
completes or until it has invoked spend()
enough to
exhaust the budget provided. If the future never called
spend()
, this function will not return until the future
has completed.
This function returns a Future
which must be awaited to execute the
function.
This implementation is runtime agnostic.
Panics
Panics when called within from within future
or any code invoked by
future
.
sourcepub fn budget(&self) -> usize
pub fn budget(&self) -> usize
Retrieves the current budget.
This function should only be called by code that is guaranteed to be running by this executor. When called outside of code run by this executor, this function will.
sourcepub fn spend(&self, amount: usize) -> SpendBudget<'_, Budget>ⓘNotable traits for SpendBudget<'a, Budget>impl<'a, Budget> Future for SpendBudget<'a, Budget> where
Budget: Budgetable, type Output = ();
pub fn spend(&self, amount: usize) -> SpendBudget<'_, Budget>ⓘNotable traits for SpendBudget<'a, Budget>impl<'a, Budget> Future for SpendBudget<'a, Budget> where
Budget: Budgetable, type Output = ();
Budget: Budgetable, type Output = ();
Spends amount
from the curent budget.
This function returns a future which must be awaited.
Trait Implementations
sourceimpl<Budget: Clone> Clone for Context<Budget> where
Budget: Budgetable,
impl<Budget: Clone> Clone for Context<Budget> where
Budget: Budgetable,
Auto Trait Implementations
impl<Budget> !RefUnwindSafe for Context<Budget>
impl<Budget> !Send for Context<Budget>
impl<Budget> !Sync for Context<Budget>
impl<Budget> Unpin for Context<Budget>
impl<Budget> !UnwindSafe for Context<Budget>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more