Skip to content

minor refactoring #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion chatty-tcp/src/connect/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::io::Write;
use std::process;
use tokio::io::{stdin, AsyncBufReadExt, AsyncWriteExt, BufReader};
use tokio::net::tcp::OwnedWriteHalf;
use tokio::select;
use tokio::signal;
use tracing::debug;

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

loop {
tokio::select! {
select! {
// Handle input from the user
line = reader.next_line() => {
if let Ok(Some(line)) = line {
Expand Down
4 changes: 2 additions & 2 deletions chatty-tcp/src/listen/command.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::listen::response::{
send_from_broadcast_channel_task, send_response, send_to_broadcast_channel,
send_from_broadcast_channel, send_response, send_to_broadcast_channel,
};
use crate::listen::state::RoomState;
use anyhow::Result;
Expand Down Expand Up @@ -45,7 +45,7 @@ pub async fn process_command(

let chat_response = if !user_already_exist {
let rx = room_state.tx.subscribe();
let send_task_handle = tokio::spawn(send_from_broadcast_channel_task(
let send_task_handle = tokio::spawn(send_from_broadcast_channel(
writer.clone(),
rx,
username.clone(),
Expand Down
6 changes: 3 additions & 3 deletions chatty-tcp/src/listen/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub async fn send_to_broadcast_channel(
Ok(())
}

pub async fn send_from_broadcast_channel_task(
pub async fn send_from_broadcast_channel(
writer: Arc<Mutex<OwnedWriteHalf>>,
mut rx: broadcast::Receiver<ChatResponse>,
username: String,
Expand Down Expand Up @@ -99,7 +99,7 @@ mod tests {

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

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

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

let (mut stream, _) = assert_ok!(listener.accept().await);
Expand Down
Loading