aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf52840/src/bin/self_spawn_current_executor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/nrf52840/src/bin/self_spawn_current_executor.rs')
-rw-r--r--examples/nrf52840/src/bin/self_spawn_current_executor.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/nrf52840/src/bin/self_spawn_current_executor.rs b/examples/nrf52840/src/bin/self_spawn_current_executor.rs
new file mode 100644
index 000000000..8a179886c
--- /dev/null
+++ b/examples/nrf52840/src/bin/self_spawn_current_executor.rs
@@ -0,0 +1,22 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::{info, unwrap};
6use embassy_executor::Spawner;
7use embassy_time::{Duration, Timer};
8use {defmt_rtt as _, panic_probe as _};
9
10#[embassy_executor::task(pool_size = 2)]
11async fn my_task(n: u32) {
12 Timer::after(Duration::from_secs(1)).await;
13 info!("Spawning self! {}", n);
14 unwrap!(Spawner::for_current_executor().await.spawn(my_task(n + 1)));
15}
16
17#[embassy_executor::main]
18async fn main(spawner: Spawner) {
19 let _p = embassy_nrf::init(Default::default());
20 info!("Hello World!");
21 unwrap!(spawner.spawn(my_task(0)));
22}