mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-07 00:00:08 +02:00
sync: bounded channel can not have 0 size (#879)
This commit is contained in:
committed by
Carl Lerche
parent
e1a07ce50c
commit
95b0eec8af
@@ -111,6 +111,7 @@ pub struct RecvError(());
|
|||||||
/// }));
|
/// }));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn channel<T>(buffer: usize) -> (Sender<T>, Receiver<T>) {
|
pub fn channel<T>(buffer: usize) -> (Sender<T>, Receiver<T>) {
|
||||||
|
assert_eq!(buffer >= 1, true);
|
||||||
let semaphore = (::semaphore::Semaphore::new(buffer), buffer);
|
let semaphore = (::semaphore::Semaphore::new(buffer), buffer);
|
||||||
let (tx, rx) = chan::channel(semaphore);
|
let (tx, rx) = chan::channel(semaphore);
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ fn send_recv_with_buffer() {
|
|||||||
assert!(val.is_none());
|
assert!(val.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn buffer_gteq_one() {
|
||||||
|
mpsc::channel::<i32>(0);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn send_recv_unbounded() {
|
fn send_recv_unbounded() {
|
||||||
let (mut tx, mut rx) = mpsc::unbounded_channel::<i32>();
|
let (mut tx, mut rx) = mpsc::unbounded_channel::<i32>();
|
||||||
|
|||||||
Reference in New Issue
Block a user