Skip to content

Commit 86ac4d5

Browse files
committed
Minor refactor to reduce nesting
1 parent dc0c5f8 commit 86ac4d5

1 file changed

Lines changed: 27 additions & 26 deletions

File tree

src/main.rs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -100,36 +100,37 @@ async fn maybe_run_until_exit(args: &argv::Args, procs: &SharedProcs) {
100100
}
101101

102102
async fn maybe_run_until_idle(args: &argv::Args, procs: &SharedProcs) {
103-
if args.wait {
104-
if args.agent {
105-
// For --wait --agent: wait for exactly one run to be assigned, then disconnect
106-
// First, wait for at least one process to be assigned (work arrives)
107-
while procs.is_empty() {
108-
// Wait for work to be assigned or shutdown signal
109-
tokio::select! {
110-
_ = procs.wait_for_shutdown() => return,
111-
_ = tokio::time::sleep(tokio::time::Duration::from_millis(100)) => {},
112-
}
103+
if !args.wait {
104+
return;
105+
}
106+
if args.agent {
107+
// For --wait --agent: wait for exactly one run to be assigned, then disconnect
108+
// First, wait for at least one process to be assigned (work arrives)
109+
while procs.is_empty() {
110+
// Wait for work to be assigned or shutdown signal
111+
tokio::select! {
112+
_ = procs.wait_for_shutdown() => return,
113+
_ = tokio::time::sleep(tokio::time::Duration::from_millis(100)) => {},
113114
}
115+
}
114116

115-
// Work has been assigned! Set shutdown to Idling to prevent accepting more work
116-
procs.set_shutdown(shutdown::State::Idling);
117+
// Work has been assigned! Set shutdown to Idling to prevent accepting more work
118+
procs.set_shutdown(shutdown::State::Idling);
117119

118-
// Now wait for the single assigned process to complete and be deleted
119-
tokio::select! {
120-
_ = procs.wait_idle() => {},
121-
_ = procs.wait_for_shutdown() => {},
122-
};
120+
// Now wait for the single assigned process to complete and be deleted
121+
tokio::select! {
122+
_ = procs.wait_idle() => {},
123+
_ = procs.wait_for_shutdown() => {},
124+
};
123125

124-
// Work completed, agent should disconnect (Done state will be set by check_idling())
125-
} else {
126-
// Non-agent mode: just wait until idle then exit
127-
tokio::select! {
128-
_ = procs.wait_idle() => {},
129-
_ = procs.wait_for_shutdown() => {},
130-
};
131-
procs.set_shutdown(shutdown::State::Done);
132-
}
126+
// Work completed, agent should disconnect (Done state will be set by check_idling())
127+
} else {
128+
// Non-agent mode: just wait until idle then exit
129+
tokio::select! {
130+
_ = procs.wait_idle() => {},
131+
_ = procs.wait_for_shutdown() => {},
132+
};
133+
procs.set_shutdown(shutdown::State::Done);
133134
}
134135
}
135136

0 commit comments

Comments
 (0)