diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-04-26 19:08:18 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-04-26 19:08:18 +0200 |
| commit | 9e897cbea92dc9b99a65802cc4e0661919001be1 (patch) | |
| tree | f68a158905b69141a2595693e500a75f5b055b31 /examples/nrf/src/bin/self_spawn_current_executor.rs | |
| parent | a39d796c3de9c96ea4df6b9da525cb0d5ef60fc0 (diff) | |
executor: Add `Spawner::for_current_executor`.
Diffstat (limited to 'examples/nrf/src/bin/self_spawn_current_executor.rs')
| -rw-r--r-- | examples/nrf/src/bin/self_spawn_current_executor.rs | 24 |
1 files changed, 24 insertions, 0 deletions
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 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::{info, unwrap}; | ||
| 6 | use embassy::executor::Spawner; | ||
| 7 | use embassy::time::{Duration, Timer}; | ||
| 8 | use embassy_nrf::Peripherals; | ||
| 9 | |||
| 10 | use defmt_rtt as _; // global logger | ||
| 11 | use panic_probe as _; | ||
| 12 | |||
| 13 | #[embassy::task(pool_size = 2)] | ||
| 14 | async fn my_task(n: u32) { | ||
| 15 | Timer::after(Duration::from_secs(1)).await; | ||
| 16 | info!("Spawning self! {}", n); | ||
| 17 | unwrap!(Spawner::for_current_executor().await.spawn(my_task(n + 1))); | ||
| 18 | } | ||
| 19 | |||
| 20 | #[embassy::main] | ||
| 21 | async fn main(spawner: Spawner, _p: Peripherals) { | ||
| 22 | info!("Hello World!"); | ||
| 23 | unwrap!(spawner.spawn(my_task(0))); | ||
| 24 | } | ||
