async_executors/iface/
yield_now.rs1use
2{
3 std::{ future::Future, pin::Pin, task::{ Context, Poll } } ,
4 blanket::blanket,
5};
6
7#[ blanket( derive(Ref, Mut, Arc, Rc, Box) ) ]
18pub trait YieldNow
20{
21 fn yield_now( &self ) -> YieldNowFut
24 {
25 YieldNowFut{ done: false }
26 }
27}
28
29
30
31#[must_use = "YieldNowFut doesn't do anything unless polled or awaited."]
34#[ derive( Debug, Copy, Clone ) ]
36pub struct YieldNowFut
38{
39 pub(crate) done: bool,
40}
41
42
43impl Future for YieldNowFut
44{
45 type Output = ();
46
47 fn poll( mut self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<()>
48 {
49 if self.done
50 {
51 return Poll::Ready(());
52 }
53
54 self.done = true;
55 cx.waker().wake_by_ref();
56 Poll::Pending
57 }
58}