mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-25 12:00:35 +00:00
sync: fix sync::broadcast::Sender<T>::closed()
doctest (#7090)
The test's previous iteration could sometimes flake since we didn't await the completion of the first task. Since the tasks only existed to `move` the relevant `rx`'s in, to force a drop, we can omit them entirely and drop the `rx`s via `drop()`. This prevents any scheduling-related flakes.
This commit is contained in:
parent
dabae570b1
commit
435e39001b
@ -825,17 +825,14 @@ impl<T> Sender<T> {
|
||||
/// let (tx, mut rx1) = broadcast::channel::<u32>(16);
|
||||
/// let mut rx2 = tx.subscribe();
|
||||
///
|
||||
/// tokio::spawn(async move {
|
||||
/// assert_eq!(rx1.recv().await.unwrap(), 10);
|
||||
/// });
|
||||
///
|
||||
/// let _ = tx.send(10);
|
||||
///
|
||||
/// assert_eq!(rx1.recv().await.unwrap(), 10);
|
||||
/// drop(rx1);
|
||||
/// assert!(tx.closed().now_or_never().is_none());
|
||||
///
|
||||
/// let _ = tokio::spawn(async move {
|
||||
/// assert_eq!(rx2.recv().await.unwrap(), 10);
|
||||
/// }).await;
|
||||
///
|
||||
/// assert_eq!(rx2.recv().await.unwrap(), 10);
|
||||
/// drop(rx2);
|
||||
/// assert!(tx.closed().now_or_never().is_some());
|
||||
/// }
|
||||
/// ```
|
||||
|
Loading…
x
Reference in New Issue
Block a user