INNER CODE UNIT · Rust
connect_tcp
ilya-zlobintsev/LACT · lact-client/src/lib.rs:60
pub async fn connect_tcp(addr: impl ToSocketAddrs) -> anyhow::Result<Self> {
let stream = TcpConnection::connect(addr).await?;
Ok(Self {
stream: Rc::new(Mutex::new(stream)),
embedded: false,
reconnect: true,
status_tx: broadcast::Sender::new(STATUS_MSG_CHANNEL_SIZE),
})
}
pub fn from_stream(stream: UnixStream, embedded: bool) -> anyhow::Result<Self> {
let connection = UnixConnection::try_from(stream)?;
Ok(Self {
stream: Rc::new(Mutex::new(Box::new(connection))),
embedded,
reconnect: false,
status_tx: broadcast::Sender::new(STATUS_MSG_CHANNEL_SIZE),