Skip to content

Commit

Permalink
Remove unnessecary Shutdown message.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcamiel authored and hurl-bot committed Oct 25, 2024
1 parent e8e5f2f commit f1a35a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 0 additions & 2 deletions packages/hurl/src/parallel/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ pub enum WorkerMessage {
Running(RunningMsg),
/// Sent when the Hurl file is completed, whether successful or failed.
Completed(CompletedMsg),
/// Sent when worker thread is disconnected (for graceful shutdown).
ShutDown,
}

/// A message sent from worker to runner when the input file can't be read.
Expand Down
4 changes: 1 addition & 3 deletions packages/hurl/src/parallel/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@ impl ParallelRunner {
}
}
}
// Worker has been shutdown.
WorkerMessage::ShutDown => {}
}
}

Expand All @@ -283,7 +281,7 @@ impl ParallelRunner {
drop(self.tx.take());
for worker in &mut self.workers {
if let Some(thread) = worker.0.take_thread() {
let _ = thread.join().unwrap();
thread.join().unwrap();
}
}

Expand Down
16 changes: 8 additions & 8 deletions packages/hurl/src/parallel/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*
*/
use std::sync::mpsc::{Receiver, SendError, Sender};
use std::sync::mpsc::{Receiver, Sender};
use std::sync::{Arc, Mutex};
use std::{fmt, thread};

Expand All @@ -35,7 +35,7 @@ pub struct Worker {
/// The id of this worker.
worker_id: WorkerId,
/// The thread handle of this worker.
thread: Option<thread::JoinHandle<Result<(), SendError<WorkerMessage>>>>,
thread: Option<thread::JoinHandle<()>>,
}

impl fmt::Display for Worker {
Expand Down Expand Up @@ -76,7 +76,7 @@ impl Worker {

let thread = thread::spawn(move || loop {
let Ok(job) = rx.lock().unwrap().recv() else {
return tx.send(WorkerMessage::ShutDown);
return;
};
// In parallel execution, standard output and standard error messages are buffered
// (in sequential mode, we'll use immediate standard output and error).
Expand All @@ -95,7 +95,8 @@ impl Worker {
Ok(c) => c,
Err(e) => {
let msg = IOErrorMsg::new(worker_id, &job, e);
return tx.send(WorkerMessage::IOError(msg));
_ = tx.send(WorkerMessage::IOError(msg));
return;
}
};

Expand All @@ -106,7 +107,8 @@ impl Worker {
Err(e) => {
logger.error_parsing_rich(&content, Some(&job.filename), &e);
let msg = ParsingErrorMsg::new(worker_id, &job, &logger.stderr);
return tx.send(WorkerMessage::ParsingError(msg));
_ = tx.send(WorkerMessage::ParsingError(msg));
return;
}
};

Expand Down Expand Up @@ -140,9 +142,7 @@ impl Worker {
}

/// Takes the thread out of the worker, leaving a None in its place.
pub fn take_thread(
&mut self,
) -> Option<thread::JoinHandle<Result<(), SendError<WorkerMessage>>>> {
pub fn take_thread(&mut self) -> Option<thread::JoinHandle<()>> {
self.thread.take()
}
}
Expand Down

0 comments on commit f1a35a0

Please sign in to comment.