use std::marker::PhantomData;
use std::sync::Arc;
use super::core::UnifiedChannel;
use crate::channel::error::ChannelError;
use crate::channel::stats::ChannelStatistics;
pub struct UnifiedReceiver<T> {
pub(crate) channel: Arc<UnifiedChannel<T>>,
pub(crate) _phantom: PhantomData<T>,
}
impl<T> UnifiedReceiver<T> {
pub fn recv(&self) -> Result<T, ChannelError> {
self.channel.recv()
}
pub fn try_recv(&self) -> Result<T, ChannelError> {
self.channel.recv()
}
pub fn recv_batch(&self, max_count: usize) -> Vec<T> {
self.channel.recv_batch(max_count)
}
pub fn is_closed(&self) -> bool {
self.channel.is_closed()
}
pub fn stats(&self) -> ChannelStatistics {
self.channel.stats()
}
}
impl<T> Clone for UnifiedReceiver<T> {
fn clone(&self) -> Self {
Self {
channel: self.channel.clone(),
_phantom: PhantomData,
}
}
}
unsafe impl<T: Send> Send for UnifiedReceiver<T> {}
unsafe impl<T: Send> Sync for UnifiedReceiver<T> {}