simplify launch_tasks loop
@@ -43,14 +43,10 @@ pub async fn user_main(
}
}
- // Repeatedly loop through all available tasks in a random order.
- let mut thread_continue: bool = true;
- if thread_user.weighted_tasks.is_empty() {
- // Handle the edge case where a load test doesn't define any normal tasks.
- thread_continue = false;
- }
+ // If normal tasks are defined, loop launching tasks until parent tells us to stop.
+ if !thread_user.weighted_tasks.is_empty() {
let mut position;
- while thread_continue {
+ 'launch_tasks: loop {
// Start at the first task in thread_user.weighted_tasks.
position = 0;
thread_user.position.store(position, Ordering::SeqCst);
@@ -80,10 +76,9 @@ pub async fn user_main(
let mut message = thread_receiver.try_recv();
while message.is_ok() {
match message.unwrap() {
- // Time to exit.
+ // Time to exit, break out of launch_tasks loop.
GooseUserCommand::Exit => {
- // No need to reset per-thread counters, we're exiting and memory will be freed
- thread_continue = false;
+ break 'launch_tasks;
}
command => {
debug!("ignoring unexpected GooseUserCommand: {:?}", command);
@@ -91,7 +86,7 @@ pub async fn user_main(
}
message = thread_receiver.try_recv();
}
- if thread_continue && thread_user.max_wait > 0 {
+ if thread_user.max_wait > 0 {
let sleep_duration = time::Duration::from_secs(1);
debug!(
"user {} from {} sleeping {:?} second...",
@@ -107,16 +102,12 @@ pub async fn user_main(
}
}
- // Break out of this loop if we've been told to exit.
- if !thread_continue {
- break;
- }
-
// Move to the next task in thread_user.weighted_tasks.
position += 1;
thread_user.position.store(position, Ordering::SeqCst);
}
}
+ }
// User is exiting, first invoke the weighted on_stop tasks.
if !thread_user.weighted_on_stop_tasks.is_empty() {
