Skip to content

Commit ab68172

Browse files
committed
minor refactoring
1 parent a0256a3 commit ab68172

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

chatty-tcp/src/connect/command.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::io::Write;
66
use std::process;
77
use tokio::io::{stdin, AsyncBufReadExt, AsyncWriteExt, BufReader};
88
use tokio::net::tcp::OwnedWriteHalf;
9+
use tokio::select;
910
use tokio::signal;
1011
use tracing::debug;
1112

@@ -21,7 +22,7 @@ pub async fn send_command(writer_half: OwnedWriteHalf, username: String) -> Resu
2122
stdout().flush()?;
2223

2324
loop {
24-
tokio::select! {
25+
select! {
2526
// Handle input from the user
2627
line = reader.next_line() => {
2728
if let Ok(Some(line)) = line {

chatty-tcp/src/listen/command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::listen::response::{
2-
send_from_broadcast_channel_task, send_response, send_to_broadcast_channel,
2+
send_from_broadcast_channel, send_response, send_to_broadcast_channel,
33
};
44
use crate::listen::state::RoomState;
55
use anyhow::Result;
@@ -45,7 +45,7 @@ pub async fn process_command(
4545

4646
let chat_response = if !user_already_exist {
4747
let rx = room_state.tx.subscribe();
48-
let send_task_handle = tokio::spawn(send_from_broadcast_channel_task(
48+
let send_task_handle = tokio::spawn(send_from_broadcast_channel(
4949
writer.clone(),
5050
rx,
5151
username.clone(),

chatty-tcp/src/listen/response.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub async fn send_to_broadcast_channel(
1919
Ok(())
2020
}
2121

22-
pub async fn send_from_broadcast_channel_task(
22+
pub async fn send_from_broadcast_channel(
2323
writer: Arc<Mutex<OwnedWriteHalf>>,
2424
mut rx: broadcast::Receiver<ChatResponse>,
2525
username: String,
@@ -99,7 +99,7 @@ mod tests {
9999

100100
let writer = Arc::new(Mutex::new(writer_half));
101101
let _handle = tokio::spawn(async move {
102-
assert_ok!(send_from_broadcast_channel_task(writer, rx, "alice".to_string()).await);
102+
assert_ok!(send_from_broadcast_channel(writer, rx, "alice".to_string()).await);
103103
});
104104

105105
let (mut stream, _) = assert_ok!(listener.accept().await);
@@ -130,7 +130,7 @@ mod tests {
130130

131131
let writer = Arc::new(Mutex::new(writer_half));
132132
let _handle = tokio::spawn(async move {
133-
assert_ok!(send_from_broadcast_channel_task(writer, rx, "alice".to_string()).await);
133+
assert_ok!(send_from_broadcast_channel(writer, rx, "alice".to_string()).await);
134134
});
135135

136136
let (mut stream, _) = assert_ok!(listener.accept().await);

0 commit comments

Comments
 (0)