Is it valid to wake a Rust future while it's being polled?
问题 I'd like to be able to sleep my future for a single "frame" so that other work can happen. Is this a valid implementation of this idea? use std::future::Future; use std::task::{Context, Poll}; use std::pin::Pin; struct Yield { yielded: bool, } impl Future for Yield { type Output = (); fn poll(mut self: Pin<&mut Self>, ctx: &mut Context) -> Poll<()> { if self.yielded { Poll::Ready(()) } else { self.yielded = true; // This is the part I'm concerned about ctx.waker().wake_by_ref(); Poll::Pending