Struct budget_executor::blocking::singlethreaded::Runtime
source · [−]pub struct Runtime<Budget>(_)
where
Budget: Budgetable;
Expand description
A lightweight asynchronous runtime that runs a future while keeping track of a budget.
Regardless of whether the threadsafe or single-threaded versions of the Runtime are used, this Runtime will always be a single-threaded runtime. The benefit of using the threadsafe runtime is to be able to move paused runtimes between different threads or allow the running futures to be woken by external threads.
Implementations
sourceimpl<Budget> Runtime<Budget> where
Budget: Budgetable,
impl<Budget> Runtime<Budget> where
Budget: Budgetable,
sourcepub fn run_with_budget<F>(
future: impl FnOnce(Self) -> F,
initial_budget: Budget
) -> Progress<Budget, F> where
Budget: Budgetable,
F: Future,
pub fn run_with_budget<F>(
future: impl FnOnce(Self) -> F,
initial_budget: Budget
) -> Progress<Budget, F> where
Budget: Budgetable,
F: Future,
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 spawn<F: Future + 'static>(&self, future: F) -> TaskHandle<F::Output>ⓘNotable traits for TaskHandle<Output>impl<Output> Future for TaskHandle<Output> where
Output: Unpin + 'static, type Output = Output;
pub fn spawn<F: Future + 'static>(&self, future: F) -> TaskHandle<F::Output>ⓘNotable traits for TaskHandle<Output>impl<Output> Future for TaskHandle<Output> where
Output: Unpin + 'static, type Output = Output;
Output: Unpin + 'static, type Output = Output;
Schedules future
to run.
This runtime will only execute one future at any given
moment in time. Context switches between futures will only
happen when the running future yields control at an await
.
Returns a handle that can be .await
ed to wait for the task
to complete.
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 Runtime<Budget> where
Budget: Budgetable,
impl<Budget: Clone> Clone for Runtime<Budget> where
Budget: Budgetable,
Auto Trait Implementations
impl<Budget> !RefUnwindSafe for Runtime<Budget>
impl<Budget> !Send for Runtime<Budget>
impl<Budget> !Sync for Runtime<Budget>
impl<Budget> Unpin for Runtime<Budget>
impl<Budget> !UnwindSafe for Runtime<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