Struct edge_executor::Executor
source · pub struct Executor<'a, const C: usize, M, S = Local> { /* private fields */ }
Expand description
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 Monitor 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 implementation for Monitor based on condvar, compatible with Rust STD (for cases where notifying from / running in ISRs is not important).
- Out of the box implementation for Monitor based on WASM event loop, compatible with WASM
Implementations§
source§impl<'a, const C: usize, M, S> Executor<'a, C, M, S>where
M: Monitor,
impl<'a, const C: usize, M, S> Executor<'a, C, M, S>where M: Monitor,
pub fn new() -> Selfwhere M: Default,
pub fn wrap(monitor: M) -> Self
pub fn spawn_detached<F, T>(&self, fut: F) -> Result<&Self, SpawnError>where F: Future<Output = T> + Send + 'a, T: 'a,
pub fn spawn_collect<F, T>( &self, fut: F, collector: &mut Vec<Task<T>, C> ) -> Result<&Self, SpawnError>where F: Future<Output = T> + Send + 'a, T: 'a,
pub fn spawn<F, T>(&self, fut: F) -> Result<Task<T>, SpawnError>where F: Future<Output = T> + Send + 'a, T: 'a,
pub unsafe fn spawn_unchecked<F, T>( &self, fut: F ) -> Result<Task<T>, SpawnError>where F: Future<Output = T>,
pub fn poll_one(&self) -> Poll<()>
pub fn poll<B>(&self, condition: B) -> Poll<()>where B: Fn() -> bool,
pub fn drop_tasks<T>(&self, tasks: T)
pub fn start<B, F>(&'static self, condition: B, finished: F)where M: Start, B: Fn() -> bool + 'static, F: FnOnce() + 'static,
pub fn run<B>(&self, condition: B)where M: Wait, B: Fn() -> bool,
pub fn run_tasks<B, T>(&self, condition: B, tasks: T)where M: Wait, B: Fn() -> bool,
pub fn wait(&self)where M: Wait,
source§impl<'a, const C: usize, M> Executor<'a, C, M, Local>where
M: Monitor,
impl<'a, const C: usize, M> Executor<'a, C, M, Local>where M: Monitor,
pub fn spawn_local_detached<F, T>(&self, fut: F) -> Result<&Self, SpawnError>where F: Future<Output = T> + 'a, T: 'a,
pub fn spawn_local_collect<F, T>( &self, fut: F, collector: &mut Vec<Task<T>, C> ) -> Result<&Self, SpawnError>where F: Future<Output = T> + 'a, T: 'a,
pub fn spawn_local<F, T>(&self, fut: F) -> Result<Task<T>, SpawnError>where F: Future<Output = T> + 'a, T: 'a,
Trait Implementations§
Auto Trait Implementations§
impl<'a, const C: usize, M, S = *const ()> !RefUnwindSafe for Executor<'a, C, M, S>
impl<'a, const C: usize, M, S> Send for Executor<'a, C, M, S>where M: Send, S: Send,
impl<'a, const C: usize, M, S = *const ()> !Sync for Executor<'a, C, M, S>
impl<'a, const C: usize, M, S> Unpin for Executor<'a, C, M, S>where M: Unpin, S: Unpin,
impl<'a, const C: usize, M, S = *const ()> !UnwindSafe for Executor<'a, C, M, S>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more