From 9e897cbea92dc9b99a65802cc4e0661919001be1 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 26 Apr 2022 19:08:18 +0200 Subject: executor: Add `Spawner::for_current_executor`. --- .../nrf/src/bin/self_spawn_current_executor.rs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/nrf/src/bin/self_spawn_current_executor.rs (limited to 'examples/nrf/src/bin/self_spawn_current_executor.rs') diff --git a/examples/nrf/src/bin/self_spawn_current_executor.rs b/examples/nrf/src/bin/self_spawn_current_executor.rs new file mode 100644 index 000000000..4850d295d --- /dev/null +++ b/examples/nrf/src/bin/self_spawn_current_executor.rs @@ -0,0 +1,24 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::{info, unwrap}; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; +use embassy_nrf::Peripherals; + +use defmt_rtt as _; // global logger +use panic_probe as _; + +#[embassy::task(pool_size = 2)] +async fn my_task(n: u32) { + Timer::after(Duration::from_secs(1)).await; + info!("Spawning self! {}", n); + unwrap!(Spawner::for_current_executor().await.spawn(my_task(n + 1))); +} + +#[embassy::main] +async fn main(spawner: Spawner, _p: Peripherals) { + info!("Hello World!"); + unwrap!(spawner.spawn(my_task(0))); +} -- cgit