Skip to content

Commit 4daac72

Browse files
committed
Replace body of tokio::select with an enum
1 parent 56def28 commit 4daac72

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

compiler/base/orchestrator/src/coordinator.rs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,18 +1842,33 @@ impl Container {
18421842
let mut stdin_open = true;
18431843

18441844
loop {
1845-
select! {
1846-
() = &mut cancelled => {
1845+
enum Event {
1846+
Cancelled,
1847+
Stdin(Option<String>),
1848+
FromWorker(WorkerMessage),
1849+
}
1850+
use Event::*;
1851+
1852+
let event = select! {
1853+
() = &mut cancelled => Cancelled,
1854+
1855+
stdin = stdin_rx.recv(), if stdin_open => Stdin(stdin),
1856+
1857+
Some(container_msg) = from_worker_rx.recv() => FromWorker(container_msg),
1858+
1859+
else => return UnexpectedEndOfMessagesSnafu.fail(),
1860+
};
1861+
1862+
match event {
1863+
Cancelled => {
18471864
let msg = CoordinatorMessage::Kill;
18481865
trace!(msg_name = msg.as_ref(), "processing");
18491866
to_worker_tx.send(msg).await.context(KillSnafu)?;
1850-
},
1867+
}
18511868

1852-
stdin = stdin_rx.recv(), if stdin_open => {
1869+
Stdin(stdin) => {
18531870
let msg = match stdin {
1854-
Some(stdin) => {
1855-
CoordinatorMessage::StdinPacket(stdin)
1856-
}
1871+
Some(stdin) => CoordinatorMessage::StdinPacket(stdin),
18571872

18581873
None => {
18591874
stdin_open = false;
@@ -1863,9 +1878,9 @@ impl Container {
18631878

18641879
trace!(msg_name = msg.as_ref(), "processing");
18651880
to_worker_tx.send(msg).await.context(StdinSnafu)?;
1866-
},
1881+
}
18671882

1868-
Some(container_msg) = from_worker_rx.recv() => {
1883+
FromWorker(container_msg) => {
18691884
trace!(msg_name = container_msg.as_ref(), "processing");
18701885

18711886
match container_msg {
@@ -1885,20 +1900,18 @@ impl Container {
18851900
status_tx.send(stats).await.ok(/* Receiver gone, that's OK */);
18861901
}
18871902

1888-
WorkerMessage::Error(e) =>
1889-
return Err(SerializedError2::adapt(e)).context(WorkerSnafu),
1903+
WorkerMessage::Error(e) => {
1904+
return Err(SerializedError2::adapt(e)).context(WorkerSnafu);
1905+
}
18901906

1891-
WorkerMessage::Error2(e) =>
1892-
return Err(e).context(WorkerSnafu),
1907+
WorkerMessage::Error2(e) => return Err(e).context(WorkerSnafu),
18931908

18941909
_ => {
18951910
let message = container_msg.as_ref();
1896-
return UnexpectedMessageSnafu { message }.fail()
1897-
},
1911+
return UnexpectedMessageSnafu { message }.fail();
1912+
}
18981913
}
1899-
},
1900-
1901-
else => return UnexpectedEndOfMessagesSnafu.fail(),
1914+
}
19021915
}
19031916
}
19041917
}

0 commit comments

Comments
 (0)