Make ConnTx Clone

This commit is contained in:
Joscha 2022-06-22 21:51:51 +02:00
parent 60bd6024ae
commit e87b9cb6d8

View file

@ -161,7 +161,7 @@ struct State {
impl State { impl State {
async fn run( async fn run(
ws: WsStream, ws: WsStream,
tx_canary: oneshot::Receiver<Infallible>, mut tx_canary: mpsc::UnboundedReceiver<Infallible>,
rx_canary: oneshot::Receiver<Infallible>, rx_canary: oneshot::Receiver<Infallible>,
event_tx: mpsc::UnboundedSender<Event>, event_tx: mpsc::UnboundedSender<Event>,
mut event_rx: mpsc::UnboundedReceiver<Event>, mut event_rx: mpsc::UnboundedReceiver<Event>,
@ -181,7 +181,7 @@ impl State {
}; };
select! { select! {
_ = tx_canary => (), _ = tx_canary.recv() => (),
_ = rx_canary => (), _ = rx_canary => (),
_ = Self::listen(&mut ws_rx, &event_tx) => (), _ = Self::listen(&mut ws_rx, &event_tx) => (),
_ = Self::send_ping_events(&event_tx) => (), _ = Self::send_ping_events(&event_tx) => (),
@ -357,8 +357,9 @@ impl State {
} }
} }
#[derive(Debug, Clone)]
pub struct ConnTx { pub struct ConnTx {
canary: oneshot::Sender<Infallible>, canary: mpsc::UnboundedSender<Infallible>,
event_tx: mpsc::UnboundedSender<Event>, event_tx: mpsc::UnboundedSender<Event>,
} }
@ -398,6 +399,7 @@ impl ConnTx {
} }
} }
#[derive(Debug)]
pub struct ConnRx { pub struct ConnRx {
canary: oneshot::Sender<Infallible>, canary: oneshot::Sender<Infallible>,
packet_rx: mpsc::UnboundedReceiver<Data>, packet_rx: mpsc::UnboundedReceiver<Data>,
@ -412,7 +414,7 @@ impl ConnRx {
// TODO Combine ConnTx and ConnRx and implement Stream + Sink? // TODO Combine ConnTx and ConnRx and implement Stream + Sink?
pub fn wrap(ws: WsStream) -> (ConnTx, ConnRx) { pub fn wrap(ws: WsStream) -> (ConnTx, ConnRx) {
let (tx_canary_tx, tx_canary_rx) = oneshot::channel(); let (tx_canary_tx, tx_canary_rx) = mpsc::unbounded_channel();
let (rx_canary_tx, rx_canary_rx) = oneshot::channel(); let (rx_canary_tx, rx_canary_rx) = oneshot::channel();
let (event_tx, event_rx) = mpsc::unbounded_channel(); let (event_tx, event_rx) = mpsc::unbounded_channel();
let (packet_tx, packet_rx) = mpsc::unbounded_channel(); let (packet_tx, packet_rx) = mpsc::unbounded_channel();