Simplify saving RpcClient by removing the generic connection param
This commit is contained in:
+13
-11
@@ -6,7 +6,7 @@ use postage::{
|
|||||||
prelude::{Sink, Stream},
|
prelude::{Sink, Stream},
|
||||||
};
|
};
|
||||||
use smol::{
|
use smol::{
|
||||||
io::{ReadHalf, WriteHalf},
|
io::{BoxedWriter, ReadHalf},
|
||||||
lock::Mutex,
|
lock::Mutex,
|
||||||
prelude::{AsyncRead, AsyncWrite},
|
prelude::{AsyncRead, AsyncWrite},
|
||||||
};
|
};
|
||||||
@@ -22,18 +22,18 @@ use zed_rpc::proto::{
|
|||||||
self, MessageStream, RequestMessage, SendMessage, ServerMessage, SubscribeMessage,
|
self, MessageStream, RequestMessage, SendMessage, ServerMessage, SubscribeMessage,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct RpcClient<Conn> {
|
pub struct RpcClient {
|
||||||
response_channels: Arc<Mutex<HashMap<i32, (mpsc::Sender<proto::from_server::Variant>, bool)>>>,
|
response_channels: Arc<Mutex<HashMap<i32, (mpsc::Sender<proto::from_server::Variant>, bool)>>>,
|
||||||
outgoing: Mutex<MessageStream<WriteHalf<Conn>>>,
|
outgoing: Mutex<MessageStream<BoxedWriter>>,
|
||||||
next_message_id: AtomicI32,
|
next_message_id: AtomicI32,
|
||||||
_drop_tx: barrier::Sender,
|
_drop_tx: barrier::Sender,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Conn> RpcClient<Conn>
|
impl RpcClient {
|
||||||
where
|
pub fn new<Conn>(conn: Conn, executor: Arc<Background>) -> Arc<Self>
|
||||||
Conn: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
where
|
||||||
{
|
Conn: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
||||||
pub fn new(conn: Conn, executor: Arc<Background>) -> Arc<Self> {
|
{
|
||||||
let response_channels = Arc::new(Mutex::new(HashMap::new()));
|
let response_channels = Arc::new(Mutex::new(HashMap::new()));
|
||||||
let (conn_rx, conn_tx) = smol::io::split(conn);
|
let (conn_rx, conn_tx) = smol::io::split(conn);
|
||||||
let (_drop_tx, drop_rx) = barrier::channel();
|
let (_drop_tx, drop_rx) = barrier::channel();
|
||||||
@@ -48,19 +48,21 @@ where
|
|||||||
|
|
||||||
Arc::new(Self {
|
Arc::new(Self {
|
||||||
response_channels,
|
response_channels,
|
||||||
outgoing: Mutex::new(MessageStream::new(conn_tx)),
|
outgoing: Mutex::new(MessageStream::new(Box::pin(conn_tx))),
|
||||||
_drop_tx,
|
_drop_tx,
|
||||||
next_message_id: AtomicI32::new(0),
|
next_message_id: AtomicI32::new(0),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_incoming(
|
async fn handle_incoming<Conn>(
|
||||||
conn: ReadHalf<Conn>,
|
conn: ReadHalf<Conn>,
|
||||||
mut drop_rx: barrier::Receiver,
|
mut drop_rx: barrier::Receiver,
|
||||||
response_channels: Arc<
|
response_channels: Arc<
|
||||||
Mutex<HashMap<i32, (mpsc::Sender<proto::from_server::Variant>, bool)>>,
|
Mutex<HashMap<i32, (mpsc::Sender<proto::from_server::Variant>, bool)>>,
|
||||||
>,
|
>,
|
||||||
) {
|
) where
|
||||||
|
Conn: AsyncRead + Unpin,
|
||||||
|
{
|
||||||
let dropped = drop_rx.recv();
|
let dropped = drop_rx.recv();
|
||||||
smol::pin!(dropped);
|
smol::pin!(dropped);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user