From a3b56a3764d223d96aaaa76e59e8741ffad179dc Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Sat, 31 Jul 2021 12:34:07 -0400 Subject: [PATCH] embassy-macros: Use `defmt::unwrap!` when spawning `embassy::main` But only when `defmt` feature is enabled. --- embassy-macros/src/lib.rs | 2 +- embassy/src/executor/mod.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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 { #chip_setup executor.run(|spawner| { - spawner.spawn(__embassy_main(spawner, p)).unwrap(); + spawner.must_spawn(__embassy_main(spawner, p)); }) } 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 { } } + /// Used by the `embassy_macros::main!` macro to throw an error when spawn + /// fails. This is here to allow conditional use of `defmt::unwrap!` + /// without introducing a `defmt` feature in the `embassy_macros` package, + /// which would require use of `-Z namespaced-features`. + pub fn must_spawn(&self, token: SpawnToken) -> () { + unwrap!(self.spawn(token)); + } + /// Convert this Spawner to a SendSpawner. This allows you to send the /// spawner to other threads, but the spawner loses the ability to spawn /// non-Send tasks.