use std::{future::Future, time::Duration};
use tokio::sync::mpsc::{Receiver, UnboundedReceiver};
pub trait AsyncChannelReceiver<T: Send>: Send {
fn receive(&mut self) -> impl Future<Output = Option<T>> + Send;
}
impl<TFrom: Send, TTo: From<TFrom> + Send> AsyncChannelReceiver<TTo> for UnboundedReceiver<TFrom> {
async fn receive(&mut self) -> Option<TTo> {
self.recv().await.map(Into::into)
}
}
impl<TFrom: Send, TTo: From<TFrom> + Send> AsyncChannelReceiver<TTo> for Receiver<TFrom> {
async fn receive(&mut self) -> Option<TTo> {
self.recv().await.map(Into::into)
}
}
impl<T: Send> AsyncChannelReceiver<T> for () {
async fn receive(&mut self) -> Option<T> {
tokio::time::sleep(Duration::MAX).await;
None
}
}