| 354 | |
| 355 | #[tokio::test] |
| 356 | async fn concurrent_send_receive() { |
| 357 | let (tx, rx) = create(3); |
| 358 | let tx_notified = Arc::new(Notify::new()); |
| 359 | let rx_notified = Arc::clone(&tx_notified); |
| 360 | |
| 361 | let handle = tokio::spawn(async move { |
| 362 | for i in 0..5 { |
| 363 | tx.send(i).unwrap(); |
| 364 | tx_notified.notified().await; |
| 365 | } |
| 366 | }); |
| 367 | |
| 368 | let mut received = Vec::new(); |
| 369 | for _ in 0..5 { |
| 370 | if let Ok(value) = rx.recv().await { |
| 371 | received.push(value); |
| 372 | rx_notified.notify_one(); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | assert_eq!(received.len(), 5); |
| 377 | // Check that values are in sequence (though not necessarily starting from 0 |
| 378 | // due to potential overwrites) |
| 379 | for i in 1..received.len() { |
| 380 | assert_eq!(received[i], i); |
| 381 | } |
| 382 | handle.await.unwrap(); |
| 383 | } |
| 384 | |
| 385 | #[tokio::test] |
| 386 | async fn cancel_safety() { |