Skip to content

Commit

Permalink
chore(server): Reduce duplicate code (#2061)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto authored Nov 23, 2024
1 parent f4a879d commit 2f2afb0
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions tonic/src/transport/server/io_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,20 @@ async fn select<IO: 'static, IE>(
where
IE: Into<crate::BoxError>,
{
if tasks.is_empty() {
return match incoming.try_next().await {
let incoming_stream_future = async {
match incoming.try_next().await {
Ok(Some(stream)) => SelectOutput::Incoming(stream),
Ok(None) => SelectOutput::Done,
Err(e) => SelectOutput::TcpErr(e.into()),
};
}
};

if tasks.is_empty() {
return incoming_stream_future.await;
}

tokio::select! {
stream = incoming.try_next() => {
match stream {
Ok(Some(stream)) => SelectOutput::Incoming(stream),
Ok(None) => SelectOutput::Done,
Err(e) => SelectOutput::TcpErr(e.into()),
}
}

stream = incoming_stream_future => stream,
accept = tasks.join_next() => {
match accept.expect("JoinSet should never end") {
Ok(Ok(io)) => SelectOutput::Io(io),
Expand Down

0 comments on commit 2f2afb0

Please sign in to comment.