1
0
Fork 0
forked from wry/wry
wry/src/async_engine/ae_yield.rs
2022-05-12 22:50:33 +02:00

27 lines
571 B
Rust

use {
crate::async_engine::AsyncEngine,
std::{
future::Future,
pin::Pin,
rc::Rc,
task::{Context, Poll},
},
};
pub struct Yield {
pub(super) iteration: u64,
pub(super) queue: Rc<AsyncEngine>,
}
impl Future for Yield {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if self.queue.iteration() > self.iteration {
Poll::Ready(())
} else {
self.queue.push_yield(cx.waker().clone());
Poll::Pending
}
}
}