Replies: 1 comment 4 replies
-
I usually recommend a watch channel. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Consider an use-case where a producer wants to notify consumers about a change, even if they were doing something else at the time of the notification.
At first
Notify
andNotify::notify_waiters
seem like a fit, but it's not. Becausenotify_waiters
doesn't make the permit available for waiters that are not waiting at the time of the notification.C: subscribe to S by cloning the
Notify
P:
notifier.notify_waiters()
C:
notifier.notified().await
<<< waits even if the permit was provided aboveOne way to get the expected behavior is to use a broadcast channel with capacity of 1.
C: subscribe to S by calling
sender.subscribe()
P:
sender.send(())
C:
receiver.recv().await
<<< wakes up correctly, with eitherErr(Lagged)
orOk(())
Is there a better way of achieving this behavior?
I did find #3066 but it was closed with a partial(?) solution.
Beta Was this translation helpful? Give feedback.
All reactions