Skip to content

Commit

Permalink
sync: bounded channel can not have 0 size (tokio-rs#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
hntd187 authored and carllerche committed Feb 1, 2019
1 parent e1a07ce commit 95b0eec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions tokio-sync/src/mpsc/bounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions tokio-sync/tests/mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down

0 comments on commit 95b0eec

Please sign in to comment.