diff options
| author | Grant Miller <[email protected]> | 2024-02-14 15:57:06 -0600 |
|---|---|---|
| committer | Grant Miller <[email protected]> | 2024-02-14 15:57:06 -0600 |
| commit | 84258e168091f1cba226f2abd91fbfa5431c12c2 (patch) | |
| tree | 8fbf5ca18a69aba3764fffaacf815556d620fc21 /embassy-executor-macros | |
| parent | 5220453d85b1e0f279e94dc1627b7d2434132920 (diff) | |
wip
Diffstat (limited to 'embassy-executor-macros')
| -rw-r--r-- | embassy-executor-macros/src/macros/task.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/embassy-executor-macros/src/macros/task.rs b/embassy-executor-macros/src/macros/task.rs index 1efb2788b..82579cbbe 100644 --- a/embassy-executor-macros/src/macros/task.rs +++ b/embassy-executor-macros/src/macros/task.rs | |||
| @@ -93,10 +93,22 @@ pub fn run(args: &[NestedMeta], f: syn::ItemFn) -> Result<TokenStream, TokenStre | |||
| 93 | #[cfg(feature = "nightly")] | 93 | #[cfg(feature = "nightly")] |
| 94 | let mut task_outer: ItemFn = parse_quote! { | 94 | let mut task_outer: ItemFn = parse_quote! { |
| 95 | #visibility fn #task_ident(#fargs) -> ::embassy_executor::SpawnToken<impl Sized> { | 95 | #visibility fn #task_ident(#fargs) -> ::embassy_executor::SpawnToken<impl Sized> { |
| 96 | type Fut = impl ::core::future::Future + 'static; | 96 | trait Task { |
| 97 | type Fut: core::future::Future + 'static; | ||
| 98 | fn construct(#fargs) -> Self::Fut; | ||
| 99 | } | ||
| 100 | |||
| 101 | struct ThisTask; | ||
| 102 | impl Task for ThisTask { | ||
| 103 | type Fut = impl core::future::Future + 'static; | ||
| 104 | fn construct(#fargs) -> Self::Fut { | ||
| 105 | #task_inner_ident(#(#full_args,)*) | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 97 | const POOL_SIZE: usize = #pool_size; | 109 | const POOL_SIZE: usize = #pool_size; |
| 98 | static POOL: ::embassy_executor::raw::TaskPool<Fut, POOL_SIZE> = ::embassy_executor::raw::TaskPool::new(); | 110 | static POOL: ::embassy_executor::raw::TaskPool<<ThisTask as Task>::Fut, POOL_SIZE> = ::embassy_executor::raw::TaskPool::new(); |
| 99 | unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#full_args,)*)) } | 111 | unsafe { POOL._spawn_async_fn(move || ThisTask::construct(#(#full_args,)*)) } |
| 100 | } | 112 | } |
| 101 | }; | 113 | }; |
| 102 | #[cfg(not(feature = "nightly"))] | 114 | #[cfg(not(feature = "nightly"))] |
