use super::{TcpStream, SendFut, Error, Outgoing, Incoming};
use ::async_fifo::{Sender, Receiver};
impl<O: Send + Unpin> super::GetOutgoing<O> for Receiver<O> {
async fn get_outgoing(&mut self) -> Option<O> {
self.recv().await.ok()
}
}
impl<I: Send> super::HandleIncoming<I> for Sender<I> {
async fn handle_incoming(&mut self, incoming: I) {
self.send(incoming);
}
}
pub fn session<O, I>(tcp_stream: TcpStream) -> (impl SendFut<Result<(), Error>>, Sender<O>, Receiver<I>)
where
O: Send + Outgoing + Unpin + 'static,
I: Send + Incoming + 'static,
{
let (tx_outgoing, rx_outgoing) = ::async_fifo::new();
let (tx_incoming, rx_incoming) = ::async_fifo::new();
let task = super::raw::session(tcp_stream, tx_incoming, rx_outgoing);
(task, tx_outgoing, rx_incoming)
}