diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-04-27 04:27:42 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-04-27 04:56:41 +0200 |
| commit | 6f6c16f44924de4d71d0e5e3acc0908f2dd474e6 (patch) | |
| tree | 563881c926fd9c0fcc104d119d9c8a26d8c319d9 /embassy-macros | |
| parent | 293f54d13406850d24d1226eb77989f4fa8db9f4 (diff) | |
executor: make send-spawning only require the task args to be Send, not the whole future.
Diffstat (limited to 'embassy-macros')
| -rw-r--r-- | embassy-macros/src/macros/task.rs | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/embassy-macros/src/macros/task.rs b/embassy-macros/src/macros/task.rs index c450982c9..96932d77c 100644 --- a/embassy-macros/src/macros/task.rs +++ b/embassy-macros/src/macros/task.rs | |||
| @@ -73,23 +73,10 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke | |||
| 73 | // in the user's code. | 73 | // in the user's code. |
| 74 | #task_inner | 74 | #task_inner |
| 75 | 75 | ||
| 76 | #visibility fn #task_ident(#fargs) -> #embassy_path::executor::SpawnToken<impl ::core::future::Future + 'static> { | 76 | #visibility fn #task_ident(#fargs) -> #embassy_path::executor::SpawnToken<impl Sized> { |
| 77 | use ::core::future::Future; | 77 | type Fut = impl ::core::future::Future + 'static; |
| 78 | use #embassy_path::executor::SpawnToken; | 78 | static POOL: #embassy_path::executor::raw::TaskPool<Fut, #pool_size> = #embassy_path::executor::raw::TaskPool::new(); |
| 79 | use #embassy_path::executor::raw::TaskPool; | 79 | POOL.spawn(move || #task_inner_ident(#(#arg_names,)*)) |
| 80 | |||
| 81 | type Fut = impl Future + 'static; | ||
| 82 | |||
| 83 | static POOL: TaskPool<Fut, #pool_size> = TaskPool::new(); | ||
| 84 | |||
| 85 | // Opaque type laundering, to obscure its origin! | ||
| 86 | // Workaround for "opaque type's hidden type cannot be another opaque type from the same scope" | ||
| 87 | // https://github.com/rust-lang/rust/issues/96406 | ||
| 88 | fn launder_tait(token: SpawnToken<impl Future+'static>) -> SpawnToken<impl Future+'static> { | ||
| 89 | token | ||
| 90 | } | ||
| 91 | |||
| 92 | launder_tait(POOL.spawn(move || #task_inner_ident(#(#arg_names,)*))) | ||
| 93 | } | 80 | } |
| 94 | }; | 81 | }; |
| 95 | 82 | ||
