diff options
| author | Ben Gamari <[email protected]> | 2021-07-31 12:34:07 -0400 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-08-05 22:40:12 +0200 |
| commit | a3b56a3764d223d96aaaa76e59e8741ffad179dc (patch) | |
| tree | 44c6c97ed169f036a39b8b4e4b348199c3c84372 | |
| parent | 40e7176e13a3166b8f1e01e179ee38efe85bfa71 (diff) | |
embassy-macros: Use `defmt::unwrap!` when spawning `embassy::main`
But only when `defmt` feature is enabled.
| -rw-r--r-- | embassy-macros/src/lib.rs | 2 | ||||
| -rw-r--r-- | embassy/src/executor/mod.rs | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index d00baebfe..ddcee0cb1 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs | |||
| @@ -364,7 +364,7 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { | |||
| 364 | #chip_setup | 364 | #chip_setup |
| 365 | 365 | ||
| 366 | executor.run(|spawner| { | 366 | executor.run(|spawner| { |
| 367 | spawner.spawn(__embassy_main(spawner, p)).unwrap(); | 367 | spawner.must_spawn(__embassy_main(spawner, p)); |
| 368 | }) | 368 | }) |
| 369 | 369 | ||
| 370 | } | 370 | } |
diff --git a/embassy/src/executor/mod.rs b/embassy/src/executor/mod.rs index ee05b6760..f3c877290 100644 --- a/embassy/src/executor/mod.rs +++ b/embassy/src/executor/mod.rs | |||
| @@ -56,6 +56,14 @@ impl Spawner { | |||
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | /// Used by the `embassy_macros::main!` macro to throw an error when spawn | ||
| 60 | /// fails. This is here to allow conditional use of `defmt::unwrap!` | ||
| 61 | /// without introducing a `defmt` feature in the `embassy_macros` package, | ||
| 62 | /// which would require use of `-Z namespaced-features`. | ||
| 63 | pub fn must_spawn<F>(&self, token: SpawnToken<F>) -> () { | ||
| 64 | unwrap!(self.spawn(token)); | ||
| 65 | } | ||
| 66 | |||
| 59 | /// Convert this Spawner to a SendSpawner. This allows you to send the | 67 | /// Convert this Spawner to a SendSpawner. This allows you to send the |
| 60 | /// spawner to other threads, but the spawner loses the ability to spawn | 68 | /// spawner to other threads, but the spawner loses the ability to spawn |
| 61 | /// non-Send tasks. | 69 | /// non-Send tasks. |
