diff options
| author | Dániel Buga <[email protected]> | 2024-12-30 12:13:13 +0100 |
|---|---|---|
| committer | Dániel Buga <[email protected]> | 2024-12-30 12:13:13 +0100 |
| commit | 44217aa0924e7590aa0afabdf17babd5c2ea5b82 (patch) | |
| tree | e42f5d02f9b560610b870d802cf390518180c3c6 /cyw43/src/ioctl.rs | |
| parent | a4f8fddd696ca2e3705827ba4b3806cbadcb3134 (diff) | |
Desugar some async fns
Diffstat (limited to 'cyw43/src/ioctl.rs')
| -rw-r--r-- | cyw43/src/ioctl.rs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/cyw43/src/ioctl.rs b/cyw43/src/ioctl.rs index f8b2d9aba..af8bb695b 100644 --- a/cyw43/src/ioctl.rs +++ b/cyw43/src/ioctl.rs | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | use core::cell::{Cell, RefCell}; | 1 | use core::cell::{Cell, RefCell}; |
| 2 | use core::future::poll_fn; | 2 | use core::future::{poll_fn, Future}; |
| 3 | use core::task::{Poll, Waker}; | 3 | use core::task::{Poll, Waker}; |
| 4 | 4 | ||
| 5 | use embassy_sync::waitqueue::WakerRegistration; | 5 | use embassy_sync::waitqueue::WakerRegistration; |
| @@ -71,7 +71,7 @@ impl IoctlState { | |||
| 71 | self.wakers.borrow_mut().runner.register(waker); | 71 | self.wakers.borrow_mut().runner.register(waker); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | pub async fn wait_complete(&self) -> usize { | 74 | pub fn wait_complete(&self) -> impl Future<Output = usize> + '_ { |
| 75 | poll_fn(|cx| { | 75 | poll_fn(|cx| { |
| 76 | if let IoctlStateInner::Done { resp_len } = self.state.get() { | 76 | if let IoctlStateInner::Done { resp_len } = self.state.get() { |
| 77 | Poll::Ready(resp_len) | 77 | Poll::Ready(resp_len) |
| @@ -80,22 +80,18 @@ impl IoctlState { | |||
| 80 | Poll::Pending | 80 | Poll::Pending |
| 81 | } | 81 | } |
| 82 | }) | 82 | }) |
| 83 | .await | ||
| 84 | } | 83 | } |
| 85 | 84 | ||
| 86 | pub async fn wait_pending(&self) -> PendingIoctl { | 85 | pub fn wait_pending(&self) -> impl Future<Output = PendingIoctl> + '_ { |
| 87 | let pending = poll_fn(|cx| { | 86 | poll_fn(|cx| { |
| 88 | if let IoctlStateInner::Pending(pending) = self.state.get() { | 87 | if let IoctlStateInner::Pending(pending) = self.state.get() { |
| 88 | self.state.set(IoctlStateInner::Sent { buf: pending.buf }); | ||
| 89 | Poll::Ready(pending) | 89 | Poll::Ready(pending) |
| 90 | } else { | 90 | } else { |
| 91 | self.register_runner(cx.waker()); | 91 | self.register_runner(cx.waker()); |
| 92 | Poll::Pending | 92 | Poll::Pending |
| 93 | } | 93 | } |
| 94 | }) | 94 | }) |
| 95 | .await; | ||
| 96 | |||
| 97 | self.state.set(IoctlStateInner::Sent { buf: pending.buf }); | ||
| 98 | pending | ||
| 99 | } | 95 | } |
| 100 | 96 | ||
| 101 | pub fn cancel_ioctl(&self) { | 97 | pub fn cancel_ioctl(&self) { |
