mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-25 12:00:35 +00:00
sync: bounded channel can not have 0 size (#879)
This commit is contained in:
parent
e1a07ce50c
commit
95b0eec8af
@ -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);
|
||||
|
||||
|
@ -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>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user