1use std::future::{Future};
2use std::pin::Pin;
3use std::task::{Context, Poll};
4use std::time::{Duration};
5use crate::timer::Sleep;
6
7pub fn async_sleep(duration: Duration) -> impl Future<Output = ()> {
8 Sleep::new(duration)
9}
10
11pub fn async_sleep_ms(ms: u64) -> impl Future<Output = ()> {
12 Sleep::new(Duration::from_millis(ms))
13}
14
15struct Yield {
16 set: bool
17}
18
19impl Future for Yield {
20 type Output = ();
21
22 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
23 if self.set {
24 Poll::Ready(())
25 } else {
26 self.get_mut().set = true;
27 cx.waker().wake_by_ref();
28 Poll::Pending
29 }
30 }
31}
32
33pub fn async_yield() -> impl Future<Output = ()> {
34 Yield { set: false }
35}