mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-10 18:07:19 +00:00
refactor(gossipsub): use pop
instead of remove
Doesn't change any functionality but `pop` returns an `Option` whereas `remove` will panic on out-of-bounds. I am more comfortable with `pop` and a pattern match. Also, usage of `continue` allows us to not use an `else`. Pull-Request: #3734.
This commit is contained in:
parent
95fa913923
commit
7c85f92e31
@ -450,17 +450,17 @@ impl ConnectionHandler for Handler {
|
|||||||
) {
|
) {
|
||||||
// outbound idle state
|
// outbound idle state
|
||||||
Some(OutboundSubstreamState::WaitingOutput(substream)) => {
|
Some(OutboundSubstreamState::WaitingOutput(substream)) => {
|
||||||
if !self.send_queue.is_empty() {
|
if let Some(message) = self.send_queue.pop() {
|
||||||
let message = self.send_queue.remove(0);
|
|
||||||
self.send_queue.shrink_to_fit();
|
self.send_queue.shrink_to_fit();
|
||||||
self.outbound_substream =
|
self.outbound_substream =
|
||||||
Some(OutboundSubstreamState::PendingSend(substream, message));
|
Some(OutboundSubstreamState::PendingSend(substream, message));
|
||||||
} else {
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
self.outbound_substream =
|
self.outbound_substream =
|
||||||
Some(OutboundSubstreamState::WaitingOutput(substream));
|
Some(OutboundSubstreamState::WaitingOutput(substream));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Some(OutboundSubstreamState::PendingSend(mut substream, message)) => {
|
Some(OutboundSubstreamState::PendingSend(mut substream, message)) => {
|
||||||
match Sink::poll_ready(Pin::new(&mut substream), cx) {
|
match Sink::poll_ready(Pin::new(&mut substream), cx) {
|
||||||
Poll::Ready(Ok(())) => {
|
Poll::Ready(Ok(())) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user