Allow RpcClient to encapsulate arbitrarily many connections

This commit is contained in:
Max Brunsfeld
2021-06-15 14:12:42 -07:00
parent e88f33851e
commit 3db215418c
4 changed files with 119 additions and 83 deletions
+12 -6
View File
@@ -670,13 +670,17 @@ impl Workspace {
// a TLS stream using `native-tls`.
let stream = smol::net::TcpStream::connect(rpc_address).await?;
let rpc_client = RpcClient::new(stream, executor);
let rpc_client = RpcClient::new();
let connection_id = rpc_client.connect(stream, executor).await;
let auth_response = rpc_client
.request(proto::Auth {
user_id: user_id.parse::<u64>()?,
access_token,
})
.request(
connection_id,
proto::Auth {
user_id: user_id.parse::<u64>()?,
access_token,
},
)
.await?;
if !auth_response.credentials_valid {
Err(anyhow!("failed to authenticate with RPC server"))?;
@@ -684,7 +688,9 @@ impl Workspace {
let share_task = this.update(&mut cx, |this, cx| {
let worktree = this.worktrees.iter().next()?;
Some(worktree.update(cx, |worktree, cx| worktree.share(rpc_client, cx)))
Some(worktree.update(cx, |worktree, cx| {
worktree.share(rpc_client, connection_id, cx)
}))
});
if let Some(share_task) = share_task {