aboutsummaryrefslogtreecommitdiff
path: root/embassy-futures/src/yield_now.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-futures/src/yield_now.rs')
-rw-r--r--embassy-futures/src/yield_now.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/embassy-futures/src/yield_now.rs b/embassy-futures/src/yield_now.rs
new file mode 100644
index 000000000..1ebecb916
--- /dev/null
+++ b/embassy-futures/src/yield_now.rs
@@ -0,0 +1,25 @@
1use core::future::Future;
2use core::pin::Pin;
3use core::task::{Context, Poll};
4
5/// Yield from the current task once, allowing other tasks to run.
6pub fn yield_now() -> impl Future<Output = ()> {
7 YieldNowFuture { yielded: false }
8}
9
10struct YieldNowFuture {
11 yielded: bool,
12}
13
14impl Future for YieldNowFuture {
15 type Output = ();
16 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
17 if self.yielded {
18 Poll::Ready(())
19 } else {
20 self.yielded = true;
21 cx.waker().wake_by_ref();
22 Poll::Pending
23 }
24 }
25}