diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-04-25 20:21:32 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-04-25 20:21:32 +0000 |
| commit | a39d796c3de9c96ea4df6b9da525cb0d5ef60fc0 (patch) | |
| tree | 77db234bb173a5da49e1815e82f3dd29402db79d /examples/nrf/src/bin/self_spawn.rs | |
| parent | 97e24b056879547bb21158c2193f67ddb9e0a790 (diff) | |
| parent | 2b0e8a330b0f2be7a8943a9e5acadf8fc7f92275 (diff) | |
Merge #730
730: Executor and task macro fixes. r=Dirbaio a=Dirbaio
See individual commits.
bors r+
Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'examples/nrf/src/bin/self_spawn.rs')
| -rw-r--r-- | examples/nrf/src/bin/self_spawn.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/examples/nrf/src/bin/self_spawn.rs b/examples/nrf/src/bin/self_spawn.rs new file mode 100644 index 000000000..35e73a8dd --- /dev/null +++ b/examples/nrf/src/bin/self_spawn.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(spawner: Spawner, n: u32) { | ||
| 15 | Timer::after(Duration::from_secs(1)).await; | ||
| 16 | info!("Spawning self! {}", n); | ||
| 17 | unwrap!(spawner.spawn(my_task(spawner, 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(spawner, 0))); | ||
| 24 | } | ||
