mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00
sync: don't panic in oneshot::try_recv (#3674)
This commit is contained in:
parent
b05b9a1788
commit
f93bc9bad1
@ -672,7 +672,7 @@ impl<T> Receiver<T> {
|
||||
return Err(TryRecvError::Empty);
|
||||
}
|
||||
} else {
|
||||
panic!("called after complete");
|
||||
Err(TryRecvError::Closed)
|
||||
};
|
||||
|
||||
self.inner = None;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#![cfg(feature = "full")]
|
||||
|
||||
use tokio::sync::oneshot;
|
||||
use tokio::sync::oneshot::error::TryRecvError;
|
||||
use tokio_test::*;
|
||||
|
||||
use std::future::Future;
|
||||
@ -190,6 +191,17 @@ fn close_after_recv() {
|
||||
rx.close();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_recv_after_completion() {
|
||||
let (tx, mut rx) = oneshot::channel::<i32>();
|
||||
|
||||
tx.send(17).unwrap();
|
||||
|
||||
assert_eq!(17, rx.try_recv().unwrap());
|
||||
assert_eq!(Err(TryRecvError::Closed), rx.try_recv());
|
||||
rx.close();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drops_tasks() {
|
||||
let (mut tx, mut rx) = oneshot::channel::<i32>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user