use crate::async_rx::*;
use crate::async_tx::*;
use crate::blocking_rx::*;
use crate::blocking_tx::*;
use crate::shared::*;
macro_rules! init_share {
($flavor: expr) => {{
let send_wakers = $flavor.new_reg_sender::<true>();
let recv_wakers = $flavor.new_reg_recv::<false>();
ChannelShared::new($flavor.to_flavor(), send_wakers, recv_wakers)
}};
}
macro_rules! init_array {
($bound: expr) => {{
Array::<T>::new($bound)
}};
}
pub fn unbounded_blocking<T: Unpin>() -> (MTx<T>, Rx<T>) {
let share = init_share!(List::<T>::new());
let tx = MTx::new(share.clone());
let rx = Rx::new(share);
(tx, rx)
}
pub fn unbounded_async<T: Unpin>() -> (MTx<T>, AsyncRx<T>) {
let share = init_share!(List::<T>::new());
let tx = MTx::new(share.clone());
let rx = AsyncRx::new(share);
(tx, rx)
}
pub fn bounded_blocking<T: Unpin>(size: usize) -> (MTx<T>, Rx<T>) {
let share = init_share!(init_array!(size));
let tx = MTx::new(share.clone());
let rx = Rx::new(share);
(tx, rx)
}
pub fn bounded_async<T: Unpin>(size: usize) -> (MAsyncTx<T>, AsyncRx<T>) {
let share = init_share!(init_array!(size));
let tx = MAsyncTx::new(share.clone());
let rx = AsyncRx::new(share);
(tx, rx)
}
pub fn bounded_tx_async_rx_blocking<T: Unpin>(size: usize) -> (MAsyncTx<T>, Rx<T>) {
let share = init_share!(init_array!(size));
let tx = MAsyncTx::new(share.clone());
let rx = Rx::new(share);
(tx, rx)
}
pub fn bounded_tx_blocking_rx_async<T>(size: usize) -> (MTx<T>, AsyncRx<T>) {
let share = init_share!(init_array!(size));
let tx = MTx::new(share.clone());
let rx = AsyncRx::new(share);
(tx, rx)
}