Skip to content

Commit

Permalink
fix: receive() no longer blocks infinitely (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
simbleau authored Sep 19, 2023
1 parent a93041a commit 6db5f5a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions matchbox_socket/src/webrtc_socket/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,11 @@ impl WebRtcChannel {
///
/// Messages are removed from the socket when called.
pub fn receive(&mut self) -> Vec<(PeerId, Packet)> {
std::iter::repeat_with(|| self.rx.try_next())
.map_while(Result::ok)
.flatten()
.collect()
let mut messages = vec![];
while let Ok(Some(x)) = self.rx.try_next() {
messages.push(x);
}
messages
}

/// Send a packet to the given peer.
Expand Down

0 comments on commit 6db5f5a

Please sign in to comment.