sync: bounded channel can not have 0 size (#879)

This commit is contained in:
Stephen Carman 2019-02-01 15:54:06 -05:00 committed by Carl Lerche
parent e1a07ce50c
commit 95b0eec8af
2 changed files with 7 additions and 0 deletions

View File

@ -111,6 +111,7 @@ pub struct RecvError(());
/// }));
/// ```
pub fn channel<T>(buffer: usize) -> (Sender<T>, Receiver<T>) {
assert_eq!(buffer >= 1, true);
let semaphore = (::semaphore::Semaphore::new(buffer), buffer);
let (tx, rx) = chan::channel(semaphore);

View File

@ -65,6 +65,12 @@ fn send_recv_with_buffer() {
assert!(val.is_none());
}
#[test]
#[should_panic]
fn buffer_gteq_one() {
mpsc::channel::<i32>(0);
}
#[test]
fn send_recv_unbounded() {
let (mut tx, mut rx) = mpsc::unbounded_channel::<i32>();