sync: add watch::Receiver::wait_for
#5606
Labels
A-tokio
Area: The main tokio crate
C-feature-request
Category: A feature request.
E-easy
Call for participation: Experience needed to fix: Easy / not much
E-help-wanted
Call for participation: Help is requested to fix this issue.
M-sync
Module: tokio/sync
Correct use of
watch::Receiver
requires first checking the current value, then waiting for changes. Forgetting the first check can lead to race conditions.Consider a watch used to track shutdown notification. The following would result in the shutdown notification being lost:
We could add some APIs that make it easier to wait for specific values.
Roughly:
Then, using a watch to await a shutdown signal becomes:
I also imagine there could be other APIs, like
wait_and_map
or something that takesfn (&T) -> Option<U>
.The text was updated successfully, but these errors were encountered: