(I strugle to ask this question a few weeks now, because I think this should be easy and obvious )
I do have a struct A
which implements the Future
trait. It should be as easy as return Poll::Pending
as long as 5 seconds have not been elapsed.
So I go with:
struct A {
start: Instant,
}
impl Future for A {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
dbg!();
if Instant::now().duration_since(self.start).as_secs() > 5 {
Poll::Ready(())
} else {
Poll::Pending
}
}
}
Sure enough, If I use the futures LocalPool
it will be only triggered once, because I miss to make the waker again to be polled. According to the async book chp. 3 it should be as easy as self.waker.register(cx.waker())
(or similar).
But what is waker
? How to I can make A
to be polled again with futures LocalPool
(or ThreadPool
)? There is the LocalSpawner
, but I can't manage to register the waker again.