diff options
| author | Matthew Tran <[email protected]> | 2025-05-28 22:00:25 -0500 |
|---|---|---|
| committer | Matthew Tran <[email protected]> | 2025-05-28 23:37:17 -0500 |
| commit | a4d4f62a1e0e808ec3dd93e282f517a2f8ad9fa5 (patch) | |
| tree | 30529d5f171a70131885c840b6de040da6c5082a /embassy-executor/tests/test.rs | |
| parent | 4766cc6f9756b54bb2e25be5ba5276538ea4917b (diff) | |
Allow `-> impl Future<Output = ()>` in #[task]
Diffstat (limited to 'embassy-executor/tests/test.rs')
| -rw-r--r-- | embassy-executor/tests/test.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/embassy-executor/tests/test.rs b/embassy-executor/tests/test.rs index 78c49c071..c7ff4554c 100644 --- a/embassy-executor/tests/test.rs +++ b/embassy-executor/tests/test.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] |
| 2 | 2 | ||
| 3 | use std::boxed::Box; | 3 | use std::boxed::Box; |
| 4 | use std::future::poll_fn; | 4 | use std::future::{poll_fn, Future}; |
| 5 | use std::sync::{Arc, Mutex}; | 5 | use std::sync::{Arc, Mutex}; |
| 6 | use std::task::Poll; | 6 | use std::task::Poll; |
| 7 | 7 | ||
| @@ -74,6 +74,28 @@ fn executor_task() { | |||
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | #[test] | 76 | #[test] |
| 77 | fn executor_task_rpit() { | ||
| 78 | #[task] | ||
| 79 | fn task1(trace: Trace) -> impl Future<Output = ()> { | ||
| 80 | async move { trace.push("poll task1") } | ||
| 81 | } | ||
| 82 | |||
| 83 | let (executor, trace) = setup(); | ||
| 84 | executor.spawner().spawn(task1(trace.clone())).unwrap(); | ||
| 85 | |||
| 86 | unsafe { executor.poll() }; | ||
| 87 | unsafe { executor.poll() }; | ||
| 88 | |||
| 89 | assert_eq!( | ||
| 90 | trace.get(), | ||
| 91 | &[ | ||
| 92 | "pend", // spawning a task pends the executor | ||
| 93 | "poll task1", // poll only once. | ||
| 94 | ] | ||
| 95 | ) | ||
| 96 | } | ||
| 97 | |||
| 98 | #[test] | ||
| 77 | fn executor_task_self_wake() { | 99 | fn executor_task_self_wake() { |
| 78 | #[task] | 100 | #[task] |
| 79 | async fn task1(trace: Trace) { | 101 | async fn task1(trace: Trace) { |
