Sha256: 7ebaddfb47640ebebc894586fcdaf481c28f6247ba6118e500984760a42a5a34
Contents?: true
Size: 779 Bytes
Versions: 11
Compression:
Stored size: 779 Bytes
Contents
use core::{ future::Future, pin::Pin, task::{Context, Poll}, }; /// A small future that yields once and then returns. #[derive(Default)] pub struct Yield { yielded: bool, } impl Yield { /// Create a new `Yield`. pub fn new() -> Self { Self::default() } } impl Future for Yield { type Output = (); fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> { if self.yielded { Poll::Ready(()) } else { // Flag ourselves as yielded to return next time, and also // flag the waker that we're already ready to get // re-enqueued for another poll. self.yielded = true; cx.waker().wake_by_ref(); Poll::Pending } } }
Version data entries
11 entries across 11 versions & 1 rubygems