Skip to content

Commit

Permalink
address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
neonphog committed Oct 10, 2024
1 parent b93e474 commit 681fd98
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions crates/tx5/src/backend/go_pion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,23 @@ impl BackConRecv for GoConRecv {
}
}

struct GoWaitCon(
PubKey,
Option<Arc<tx5_connection::Conn>>,
Option<tx5_connection::ConnRecv>,
);
struct GoWaitCon {
pub_key: PubKey,
con: Option<Arc<tx5_connection::Conn>>,
con_recv: Option<tx5_connection::ConnRecv>,
}

impl BackWaitCon for GoWaitCon {
fn wait(
&mut self,
recv_limit: Arc<tokio::sync::Semaphore>,
) -> BoxFuture<'static, Result<(DynBackCon, DynBackConRecv)>> {
let con = self.1.take();
let con_recv = self.2.take();
let con = self.con.take();
let con_recv = self.con_recv.take();
Box::pin(async move {
let (con, con_recv) = match (con, con_recv) {
(_, None) | (None, _) => {
return Err(std::io::Error::other("already awaited"))
}
(Some(con), Some(con_recv)) => (con, con_recv),
_ => return Err(std::io::Error::other("already awaited")),
};

con.ready().await;
Expand All @@ -66,7 +64,7 @@ impl BackWaitCon for GoWaitCon {
}

fn pub_key(&self) -> &PubKey {
&self.0
&self.pub_key
}
}

Expand All @@ -80,8 +78,11 @@ impl BackEp for GoEp {
Box::pin(async {
let (con, con_recv) = self.0.connect(pub_key).await?;
let pub_key = con.pub_key().clone();
let wc: DynBackWaitCon =
Box::new(GoWaitCon(pub_key, Some(con), Some(con_recv)));
let wc: DynBackWaitCon = Box::new(GoWaitCon {
pub_key,
con: Some(con),
con_recv: Some(con_recv),
});
Ok(wc)
})
}
Expand All @@ -98,8 +99,11 @@ impl BackEpRecv for GoEpRecv {
Box::pin(async {
let (con, con_recv) = self.0.accept().await?;
let pub_key = con.pub_key().clone();
let wc: DynBackWaitCon =
Box::new(GoWaitCon(pub_key, Some(con), Some(con_recv)));
let wc: DynBackWaitCon = Box::new(GoWaitCon {
pub_key,
con: Some(con),
con_recv: Some(con_recv),
});
Some(wc)
})
}
Expand Down

0 comments on commit 681fd98

Please sign in to comment.