Skip to content

Comments

ready_cache: use futures::task::AtomicWaker for cancelation#669

Merged
olix0r merged 1 commit intover/rc-notifyfrom
eliza/ver/rc-notify
Jun 17, 2022
Merged

ready_cache: use futures::task::AtomicWaker for cancelation#669
olix0r merged 1 commit intover/rc-notifyfrom
eliza/ver/rc-notify

Conversation

@hawkw
Copy link
Member

@hawkw hawkw commented Jun 17, 2022

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 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.
@hawkw hawkw requested a review from olix0r June 17, 2022 16:58
@olix0r olix0r merged commit efd199d into ver/rc-notify Jun 17, 2022
@olix0r olix0r deleted the eliza/ver/rc-notify branch June 17, 2022 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants