Struct edge_executor::Executor
source · [−]Expand description
WORK IN PROGRESS
Executor
is an async executor that is useful specfically for embedded environments.
The implementation is in fact a thin wrapper around smol’s async-task crate.
Highlights:
no_std
(but does needalloc
; for ano_std
and “no_alloc” executor, look at Embassy, which statically pre-allocates all tasks); (note also that usage ofalloc
is very limited - only when a new task is being spawn, as well as the executor itself);- Does not assume an RTOS and can run completely bare-metal (or on top of an RTOS);
- Pluggable Wait & Notify mechanism which makes it ISR-friendly. In particular:
- Tasks can be woken up (and thus re-scheduled) from within an ISR;
- The executor itself can run not just in the main “thread”, but from within an ISR as well; the latter is important for bare-metal non-RTOS use-cases, as it allows - by running multiple executors - one in the main “thread” and the others - on ISR interrupts - to achieve RTOS-like pre-emptive execution by scheduling higher-priority tasks in executors that run on (higher-level) ISRs and thus pre-empt the executors scheduled on lower-level ISR and the “main thread” one; note that deploying an executor in an ISR requires the allocator to be usable from an ISR (i.e. allocation/deallocation routines should be protected by critical sections that disable/enable interrupts);
- Out of the box implementations for Wait & Notify based on condvars, compatible with Rust STD (for cases where notifying from / running in ISRs is not important).
Implementations
sourceimpl<'a, const C: usize, N, W, S> Executor<'a, C, N, W, S> where
N: NotifyFactory + RunContextFactory,
W: Wait,
impl<'a, const C: usize, N, W, S> Executor<'a, C, N, W, S> where
N: NotifyFactory + RunContextFactory,
W: Wait,
pub fn new(notify_factory: N, wait: W) -> Self
pub fn spawn_detached<F, T>(&mut self, fut: F) -> Result<&mut Self, SpawnError> where
F: Future<Output = T> + Send + 'a,
T: 'a,
pub fn spawn<F, T>(&mut self, fut: F) -> Result<Task<T>, SpawnError> where
F: Future<Output = T> + Send + 'a,
T: 'a,
pub unsafe fn spawn_unchecked<F, T>(
&mut self,
fut: F
) -> Result<Task<T>, SpawnError> where
F: Future<Output = T>,
pub fn with_context<F, T>(&mut self, run: F) -> T where
F: FnOnce(&mut Self, &RunContext) -> T,
pub fn tick(&mut self, _context: &RunContext) -> bool
pub fn wait(&mut self, _context: &RunContext)
sourceimpl<'a, const C: usize, N, W> Executor<'a, C, N, W, Local> where
N: NotifyFactory + RunContextFactory,
W: Wait,
impl<'a, const C: usize, N, W> Executor<'a, C, N, W, Local> where
N: NotifyFactory + RunContextFactory,
W: Wait,
pub fn spawn_local_detached<F, T>(
&mut self,
fut: F
) -> Result<&mut Self, SpawnError> where
F: Future<Output = T> + 'a,
T: 'a,
pub fn spawn_local<F, T>(&mut self, fut: F) -> Result<Task<T>, SpawnError> where
F: Future<Output = T> + 'a,
T: 'a,
Auto Trait Implementations
impl<'a, const C: usize, N, W, S = ()> !RefUnwindSafe for Executor<'a, C, N, W, S>
impl<'a, const C: usize, N, W, S> Send for Executor<'a, C, N, W, S> where
N: Send,
S: Send,
W: Send,
impl<'a, const C: usize, N, W, S = ()> !Sync for Executor<'a, C, N, W, S>
impl<'a, const C: usize, N, W, S> Unpin for Executor<'a, C, N, W, S> where
N: Unpin,
S: Unpin,
W: Unpin,
impl<'a, const C: usize, N, W, S = ()> !UnwindSafe for Executor<'a, C, N, W, S>
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