[][src]Crate embedded_executor

Embedded Futures Executor

This crate provides a futures executor whose only dependency is alloc.

Dependency Setup

To make https://docs.rs/ happy, this crate uses std by default. For use on embedded systems, disable default features and enable the alloc feature:

[dependencies.embedded-executor]
version = "0.2.2"
default-features = false
features = ["alloc"]

The Executor

The base executor type is AllocExecutor. To use it, you need both a RawMutex implementation and a Sleep implementation.

For convenience, SpinSleep provides a simple spinlock-based Sleep implementation, and an example spinlock RawMutex can be found in the lock_api docs. It is recommended, however, to use implementations more suited to your particular platform, such as a Sleep that calls cortex_m::asm::wfi and a RawMutex that disables/enables interrupts.

Once you have all of these pieces, it's usually easiest to create an alias for your platform-specific executor:

This example is not tested
type Executor<'a> = AllocExecutor<'a, IFreeMutex, WFISleep>;

which can then be instantiated via its new or with_capacity methods.

Spawning

Futures can be spawned either by calling AllocExecutor::spawn or by getting a alloc_executor::Spawner and calling alloc_executor::Spawner::spawn. The Spawner can also be passed to other Futures for even more spawning goodness.

Running

Running the executor is done via the AllocExecutor::run method. This will drive all spawned futures and any new futures that get spawned to completion before returning.

Modules

alloc_executor

Dynamic alloc-backed executor

Structs

AllocExecutor

Alloc-only Future executor

SpinSleep

Simple atomic spinlock sleep implementation.

Traits

Sleep

Platform-agnostic Sleep trait

Wake

Wake trait