Skip to content

Commit

Permalink
remove needless loop
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasad1 committed Nov 30, 2024
1 parent dfdf835 commit d23d92f
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions client/transport/src/ws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,16 @@ where

/// Returns a `Future` resolving when the server sent us something back.
async fn receive(&mut self) -> Result<ReceivedMessage, Self::Error> {
loop {
let mut message = Vec::new();
let recv = self.inner.receive(&mut message).await?;

match recv {
Incoming::Data(Data::Text(_)) => {
let s = String::from_utf8(message).map_err(|err| WsError::Connection(Utf8(err.utf8_error())))?;
break Ok(ReceivedMessage::Text(s));
}
Incoming::Data(Data::Binary(_)) => break Ok(ReceivedMessage::Bytes(message)),
Incoming::Pong(_) => break Ok(ReceivedMessage::Pong),
Incoming::Closed(c) => break Err(WsError::Closed(c)),
let mut message = Vec::new();

match self.inner.receive(&mut message).await? {
Incoming::Data(Data::Text(_)) => {
let s = String::from_utf8(message).map_err(|err| WsError::Connection(Utf8(err.utf8_error())))?;
Ok(ReceivedMessage::Text(s))
}
Incoming::Data(Data::Binary(_)) => Ok(ReceivedMessage::Bytes(message)),
Incoming::Pong(_) => Ok(ReceivedMessage::Pong),
Incoming::Closed(c) => Err(WsError::Closed(c)),
}
}
}
Expand Down

0 comments on commit d23d92f

Please sign in to comment.