Skip to content

Commit 3611d69

Browse files
muxers/yamux: Refactor Yamux::close to use ? (#2677)
1 parent 6e1e314 commit 3611d69

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

muxers/yamux/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use libp2p_core::muxing::{StreamMuxer, StreamMuxerEvent};
3131
use libp2p_core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
3232
use parking_lot::Mutex;
3333
use std::{
34-
fmt, io, iter,
34+
fmt, io, iter, mem,
3535
pin::Pin,
3636
task::{Context, Poll},
3737
};
@@ -179,16 +179,21 @@ where
179179

180180
fn poll_close(&self, c: &mut Context<'_>) -> Poll<YamuxResult<()>> {
181181
let mut inner = self.0.lock();
182-
if let std::task::Poll::Ready(x) = Pin::new(&mut inner.control).poll_close(c) {
183-
return Poll::Ready(x.map_err(YamuxError));
182+
183+
if let Poll::Ready(()) = Pin::new(&mut inner.control)
184+
.poll_close(c)
185+
.map_err(YamuxError)?
186+
{
187+
return Poll::Ready(Ok(()));
184188
}
185-
while let std::task::Poll::Ready(x) = inner.incoming.poll_next_unpin(c) {
186-
match x {
187-
Some(Ok(_)) => {} // drop inbound stream
188-
Some(Err(e)) => return Poll::Ready(Err(e)),
189+
190+
while let Poll::Ready(maybe_inbound_stream) = inner.incoming.poll_next_unpin(c)? {
191+
match maybe_inbound_stream {
192+
Some(inbound_stream) => mem::drop(inbound_stream),
189193
None => return Poll::Ready(Ok(())),
190194
}
191195
}
196+
192197
Poll::Pending
193198
}
194199
}

0 commit comments

Comments
 (0)