Skip to main content

Module executor

Module executor 

Source
Expand description

A mocked version of the embassy-executor crate.

§Examples

use embassy_mock::executor::Spawner;

#[embassy_executor::task]
async fn example_task() {}

// Generic over the `Spawner` trait
pub fn spawn_tasks<S: Spawner>(spawner: &S) {
    spawner.spawn(example_task()).unwrap();
}

// The real main that runs on the Embassy executor.
// #[embassy_executor::main]
// async fn main(spawner: embassy_executor::Spawner) {
//     spawn_tasks(&spawner);
// }

// The unit tests that use the `MockSpawner`.
#[cfg(test)]
mod tests {
    use super::*;
    use embassy_mock::executor::MockSpawner;

    #[test]
    fn test_spawning_of_tasks() {
        let spawner = MockSpawner::expect(1);
        spawn_tasks(&spawner);

        assert_eq!(spawner.done(), Ok(()));
    }
}

Structs§

MockSpawner
A mocked version of embassy_executor::Spawner that can be used in its place for unit tests.

Enums§

MockSpawnerError
The errors that are reported by MockSpawner.

Traits§

Spawner
The trait to replace the embassy_executor::Spawner in code to allow the MockSpawner to be used in its place for tests.