You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it is guaranteed that each invocation of wake() (or wake_by_ref()) will be followed by at least one poll() of the task to which this Waker belongs
According to std doc, when implementing an executor, I should call poll at least once whenever wake was called. But this is not the case for Shared: it can return a Poll::Ready and call wake at the same time. If I follow a poll afterwards, it will return Poll::Ready again. It seems the most correct thing to do then is to not poll at all and ignore this wake, which contradicts with the doc.
This behavior itself may not be a problem, but the doc is quite confusing.
The text was updated successfully, but these errors were encountered:
Frankly, this line in the std docs appears wrong to me:
As long as the executor keeps running and the task is not finished, it is guaranteed that each invocation of wake() (or wake_by_ref()) will be followed by at least one poll() of the task to which this Waker belongs.
There's no way Waker can guarantee that. An executor probably would do that, but the strength of the sentence should reflect that level of certainty (read: not much).
Source: have implemented and maintained serious executors.
If I've not mistaken then
Shared::poll
will wake up the very same waker that was actually polling it, and return aPoll::Ready
at the same time.futures-rs/futures-util/src/future/future/shared.rs
Lines 347 to 352 in bb63c37
Which is confusing considering what std doc was saying about
Waker::wake
protocol.According to std doc, when implementing an executor, I should call
poll
at least once wheneverwake
was called. But this is not the case forShared
: it can return aPoll::Ready
and callwake
at the same time. If I follow apoll
afterwards, it will returnPoll::Ready
again. It seems the most correct thing to do then is to notpoll
at all and ignore thiswake
, which contradicts with the doc.This behavior itself may not be a problem, but the doc is quite confusing.
The text was updated successfully, but these errors were encountered: