tokio-rs / website

Website for the Tokio project
https://tokio.rs
MIT License
229 stars 329 forks source link

Waker returns a Future, which breaks code in the "Async in depth" chapter #635

Closed RobWalt closed 2 years ago

RobWalt commented 2 years ago

In one of the last sections called "A few loose ends" the importance of updating the waker on every poll call is explained.

To solve the updating challenge, the following is proposed:

struct Delay {
    ...
   waker: Option<Arc<Mutx<Waker>>>
}

where Waker means std::task::Waker. Later in that code we repeatingly call:

...
   ... self.waker.lock().unwrap();
...

However, at the time of creation of this issue, the std::task::Waker seems to be a Future instead of an Option or a Result. This completely breaks this sections code. If we would try to resolve this by calling await on these futures in all cases (I don't really know if that makes sense at that point anyway) it doesn't work, since we do this in a synchronous function.

Darksonn commented 2 years ago

I had a look at the code snippet you are referring to and it looks correct to me. Additionally, Waker is not a Future. The thing we are calling unwrap on is the Result<MutexGuard<Waker>, PoisonError> that the lock method returns.

RobWalt commented 2 years ago

Ok, sorry I just found my error. I was using tokio::sync::Mutex on accident. Thanks for your quick reply, I'm going to close this.