ready_cache: use futures::task::AtomicWaker for cancelation#669
Merged
olix0r merged 1 commit intover/rc-notifyfrom Jun 17, 2022
Merged
ready_cache: use futures::task::AtomicWaker for cancelation#669olix0r merged 1 commit intover/rc-notifyfrom
futures::task::AtomicWaker for cancelation#669olix0r merged 1 commit intover/rc-notifyfrom
Conversation
This replaces the use of `tokio::sync::Notify` with `futures::task::AtomicWaker`. `Notify` requires the `Notified` future to be held in order to remain interested in the notification. Dropping the future returned by `Notify::notified` cancels interest in the notification. So, the current code using `Notify` is incorrect, as the `Notified` future is created on each poll and then immediately dropped, releasing interest in the wakeup. We could solve this by storing the `Notify::notified` future in the `Pending` future, but this would be a bit of a pain, as the `Notified` future borrows the `Notify`. I thought that it was a nicer alternative to just rewrite this code to use `AtomicWaker` instead. Also, `AtomicWaker` is a much simpler, lower-level primitive. It simply stores a single waker that can wake up a single task. `Notify` is capable of waking multiple tasks, either in order or all at once, which makes it more complex.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This replaces the use of
tokio::sync::Notifywithfutures::task::AtomicWaker.Notifyrequires theNotifiedfuture tobe held in order to remain interested in the notification. Dropping the
future returned by
Notify::notifiedcancels interest in thenotification. So, the current code using
Notifyis incorrect, as theNotifiedfuture is created on each poll and then immediately dropped,releasing interest in the wakeup.
We could solve this by storing the
Notify::notifiedfuture in thePendingfuture, but this would be a bit of a pain, as theNotifiedfuture borrows the
Notify. I thought that it was a nicer alternativeto just rewrite this code to use
AtomicWakerinstead.Also,
AtomicWakeris a much simpler, lower-level primitive. It simplystores a single waker that can wake up a single task.
Notifyiscapable of waking multiple tasks, either in order or all at once,
which makes it more complex.