Remove unnecessary async from Peer::add_connection

This commit is contained in:
Antonio Scandurra 2022-10-12 15:13:41 +02:00
parent cc56fa9ea6
commit ec19f0f8e9
4 changed files with 27 additions and 40 deletions

View file

@ -672,7 +672,7 @@ impl Client {
if !read_from_keychain && IMPERSONATE_LOGIN.is_none() {
write_credentials_to_keychain(&credentials, cx).log_err();
}
self.set_connection(conn, cx).await;
self.set_connection(conn, cx);
Ok(())
}
Err(EstablishConnectionError::Unauthorized) => {
@ -703,13 +703,12 @@ impl Client {
}
}
async fn set_connection(self: &Arc<Self>, conn: Connection, cx: &AsyncAppContext) {
fn set_connection(self: &Arc<Self>, conn: Connection, cx: &AsyncAppContext) {
let executor = cx.background();
log::info!("add connection to peer");
let (connection_id, handle_io, mut incoming) = self
.peer
.add_connection(conn, move |duration| executor.timer(duration))
.await;
.add_connection(conn, move |duration| executor.timer(duration));
log::info!("set status to connected {}", connection_id);
self.set_status(Status::Connected { connection_id }, cx);
cx.foreground()

View file

@ -82,7 +82,7 @@ impl FakeServer {
let (client_conn, server_conn, _) = Connection::in_memory(cx.background());
let (connection_id, io, incoming) =
peer.add_test_connection(server_conn, cx.background()).await;
peer.add_test_connection(server_conn, cx.background());
cx.background().spawn(io).detach();
let mut state = state.lock();
state.connection_id = Some(connection_id);

View file

@ -365,8 +365,7 @@ impl Server {
timer.await;
}
}
})
.await;
});
tracing::info!(%user_id, %login, %connection_id, %address, "connection opened");

View file

@ -113,7 +113,7 @@ impl Peer {
}
#[instrument(skip_all)]
pub async fn add_connection<F, Fut, Out>(
pub fn add_connection<F, Fut, Out>(
self: &Arc<Self>,
connection: Connection,
create_timer: F,
@ -326,7 +326,7 @@ impl Peer {
}
#[cfg(any(test, feature = "test-support"))]
pub async fn add_test_connection(
pub fn add_test_connection(
self: &Arc<Self>,
connection: Connection,
executor: Arc<gpui::executor::Background>,
@ -337,7 +337,6 @@ impl Peer {
) {
let executor = executor.clone();
self.add_connection(connection, move |duration| executor.timer(duration))
.await
}
pub fn disconnect(&self, connection_id: ConnectionId) {
@ -522,21 +521,17 @@ mod tests {
let (client1_to_server_conn, server_to_client_1_conn, _kill) =
Connection::in_memory(cx.background());
let (client1_conn_id, io_task1, client1_incoming) = client1
.add_test_connection(client1_to_server_conn, cx.background())
.await;
let (_, io_task2, server_incoming1) = server
.add_test_connection(server_to_client_1_conn, cx.background())
.await;
let (client1_conn_id, io_task1, client1_incoming) =
client1.add_test_connection(client1_to_server_conn, cx.background());
let (_, io_task2, server_incoming1) =
server.add_test_connection(server_to_client_1_conn, cx.background());
let (client2_to_server_conn, server_to_client_2_conn, _kill) =
Connection::in_memory(cx.background());
let (client2_conn_id, io_task3, client2_incoming) = client2
.add_test_connection(client2_to_server_conn, cx.background())
.await;
let (_, io_task4, server_incoming2) = server
.add_test_connection(server_to_client_2_conn, cx.background())
.await;
let (client2_conn_id, io_task3, client2_incoming) =
client2.add_test_connection(client2_to_server_conn, cx.background());
let (_, io_task4, server_incoming2) =
server.add_test_connection(server_to_client_2_conn, cx.background());
executor.spawn(io_task1).detach();
executor.spawn(io_task2).detach();
@ -619,12 +614,10 @@ mod tests {
let (client_to_server_conn, server_to_client_conn, _kill) =
Connection::in_memory(cx.background());
let (client_to_server_conn_id, io_task1, mut client_incoming) = client
.add_test_connection(client_to_server_conn, cx.background())
.await;
let (server_to_client_conn_id, io_task2, mut server_incoming) = server
.add_test_connection(server_to_client_conn, cx.background())
.await;
let (client_to_server_conn_id, io_task1, mut client_incoming) =
client.add_test_connection(client_to_server_conn, cx.background());
let (server_to_client_conn_id, io_task2, mut server_incoming) =
server.add_test_connection(server_to_client_conn, cx.background());
executor.spawn(io_task1).detach();
executor.spawn(io_task2).detach();
@ -719,12 +712,10 @@ mod tests {
let (client_to_server_conn, server_to_client_conn, _kill) =
Connection::in_memory(cx.background());
let (client_to_server_conn_id, io_task1, mut client_incoming) = client
.add_test_connection(client_to_server_conn, cx.background())
.await;
let (server_to_client_conn_id, io_task2, mut server_incoming) = server
.add_test_connection(server_to_client_conn, cx.background())
.await;
let (client_to_server_conn_id, io_task1, mut client_incoming) =
client.add_test_connection(client_to_server_conn, cx.background());
let (server_to_client_conn_id, io_task2, mut server_incoming) =
server.add_test_connection(server_to_client_conn, cx.background());
executor.spawn(io_task1).detach();
executor.spawn(io_task2).detach();
@ -832,9 +823,8 @@ mod tests {
let (client_conn, mut server_conn, _kill) = Connection::in_memory(cx.background());
let client = Peer::new();
let (connection_id, io_handler, mut incoming) = client
.add_test_connection(client_conn, cx.background())
.await;
let (connection_id, io_handler, mut incoming) =
client.add_test_connection(client_conn, cx.background());
let (io_ended_tx, io_ended_rx) = oneshot::channel();
executor
@ -868,9 +858,8 @@ mod tests {
let (client_conn, mut server_conn, _kill) = Connection::in_memory(cx.background());
let client = Peer::new();
let (connection_id, io_handler, mut incoming) = client
.add_test_connection(client_conn, cx.background())
.await;
let (connection_id, io_handler, mut incoming) =
client.add_test_connection(client_conn, cx.background());
executor.spawn(io_handler).detach();
executor
.spawn(async move { incoming.next().await })