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 need alloc; for a no_std and “no_alloc” executor, look at Embassy, which statically pre-allocates all tasks); (note also that usage of alloc 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,

source

pub fn new() -> Selfwhere M: Default,

source

pub fn wrap(monitor: M) -> Self

source

pub fn spawn_detached<F, T>(&self, fut: F) -> Result<&Self, SpawnError>where F: Future<Output = T> + Send + 'a, T: 'a,

source

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,

source

pub fn spawn<F, T>(&self, fut: F) -> Result<Task<T>, SpawnError>where F: Future<Output = T> + Send + 'a, T: 'a,

source

pub unsafe fn spawn_unchecked<F, T>( &self, fut: F ) -> Result<Task<T>, SpawnError>where F: Future<Output = T>,

source

pub fn poll_one(&self) -> Poll<()>

source

pub fn poll<B>(&self, condition: B) -> Poll<()>where B: Fn() -> bool,

source

pub fn drop_tasks<T>(&self, tasks: T)

source

pub fn start<B, F>(&'static self, condition: B, finished: F)where M: Start, B: Fn() -> bool + 'static, F: FnOnce() + 'static,

source

pub fn run<B>(&self, condition: B)where M: Wait, B: Fn() -> bool,

source

pub fn run_tasks<B, T>(&self, condition: B, tasks: T)where M: Wait, B: Fn() -> bool,

source

pub fn wait(&self)where M: Wait,

source§

impl<'a, const C: usize, M> Executor<'a, C, M, Local>where M: Monitor,

source

pub fn spawn_local_detached<F, T>(&self, fut: F) -> Result<&Self, SpawnError>where F: Future<Output = T> + 'a, T: 'a,

source

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,

source

pub fn spawn_local<F, T>(&self, fut: F) -> Result<Task<T>, SpawnError>where F: Future<Output = T> + 'a, T: 'a,

Trait Implementations§

source§

impl<'a, const C: usize, M, S> Default for Executor<'a, C, M, S>where M: Monitor + Default,

source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.