#[cfg(feature = "alloc")]
#[macro_export]
macro_rules! embassy_spawner {
($vis:vis $name:ident, pool_size = $pool_size:expr) => {
#[derive(Clone, Copy)]
$vis struct $name(pub ::embassy_executor::Spawner);
impl $crate::LocalSpawner for $name {
fn spawn_local<F>(&self, task: F) -> ::core::result::Result<(), $crate::SpawnError>
where
F: ::core::future::Future<Output = ()> + 'static,
{
#[::embassy_executor::task(pool_size = $pool_size)]
async fn run(
task: ::core::pin::Pin<
$crate::__private::Box<dyn ::core::future::Future<Output = ()>>,
>,
) {
task.await
}
let token = run($crate::__private::Box::pin(task)).map_err(|_| {
$crate::SpawnError::new(concat!(
stringify!($name),
": all `pool_size` tasks are running"
))
})?;
self.0.spawn(token);
::core::result::Result::Ok(())
}
}
};
}
#[cfg(not(feature = "alloc"))]
#[doc(hidden)]
#[macro_export]
macro_rules! embassy_spawner {
($($input:tt)*) => {
::core::compile_error!(
"`embassy_spawner!` needs the `alloc` feature of async-deferred, because `Deferred` \
keeps its tasks on the heap. Without a heap, use `StaticDeferred` \
(the `static-deferred` feature)."
);
};
}