fix(panic): remove panic in `close_and_flush_next` fn (#4782)
* remove panic in `close_and_flush_next` fn * Explain that `try_next()`'s documentation is wrong Co-authored-by: teor <teor@riseup.net>
This commit is contained in:
parent
cf4b2f7a67
commit
ff1c8dd4a1
|
|
@ -201,7 +201,6 @@ impl ClientRequestReceiver {
|
||||||
/// Closing the channel ensures that:
|
/// Closing the channel ensures that:
|
||||||
/// - the request stream terminates, and
|
/// - the request stream terminates, and
|
||||||
/// - task notifications are not required.
|
/// - task notifications are not required.
|
||||||
#[allow(clippy::unwrap_in_result)]
|
|
||||||
pub fn close_and_flush_next(&mut self) -> Option<InProgressClientRequest> {
|
pub fn close_and_flush_next(&mut self) -> Option<InProgressClientRequest> {
|
||||||
self.inner.close();
|
self.inner.close();
|
||||||
|
|
||||||
|
|
@ -210,10 +209,10 @@ impl ClientRequestReceiver {
|
||||||
// The request stream terminates, because the sender is closed,
|
// The request stream terminates, because the sender is closed,
|
||||||
// and the channel has a limited capacity.
|
// and the channel has a limited capacity.
|
||||||
// Task notifications are not required, because the sender is closed.
|
// Task notifications are not required, because the sender is closed.
|
||||||
self.inner
|
//
|
||||||
.try_next()
|
// Despite what its documentation says, we've seen futures::channel::mpsc::Receiver::try_next()
|
||||||
.expect("channel is closed")
|
// return an error after the channel is closed.
|
||||||
.map(Into::into)
|
self.inner.try_next().ok()?.map(Into::into)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue