aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf/src/bin/self_spawn_current_executor.rs
blob: 3c3379ce6de68bc60d3d439d6c74861644867693 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#![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 _, 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)));
}