split embassy-util into embassy-futures, embassy-sync.

This commit is contained in:
Dario Nieuwenhuis
2022-08-22 21:46:09 +02:00
parent 61356181b2
commit 21072bee48
118 changed files with 391 additions and 142 deletions

View File

@@ -0,0 +1,25 @@
use core::future::Future;
use core::pin::Pin;
use core::task::{Context, Poll};
/// Yield from the current task once, allowing other tasks to run.
pub fn yield_now() -> impl Future<Output = ()> {
YieldNowFuture { yielded: false }
}
struct YieldNowFuture {
yielded: bool,
}
impl Future for YieldNowFuture {
type Output = ();
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if self.yielded {
Poll::Ready(())
} else {
self.yielded = true;
cx.waker().wake_by_ref();
Poll::Pending
}
}
}