diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index d00baebf..ddcee0cb 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 ee05b676..f3c87729 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.