executor: Add Spawner::for_current_executor.

This commit is contained in:
Dario Nieuwenhuis
2022-04-26 19:08:18 +02:00
parent a39d796c3d
commit 9e897cbea9
3 changed files with 85 additions and 4 deletions

View File

@ -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)));
}