Skip to content

Commit cecff54

Browse files
committed
refactor: make OnClosed public, improve docs
1 parent 5ceed19 commit cecff54

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

quinn/src/connection.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -520,15 +520,14 @@ impl Connection {
520520

521521
/// Wait for the connection to be closed without keeping a strong reference to the connection
522522
///
523+
/// Returns a future that resolves, once the connection is closed, to a tuple of
524+
/// ([`ConnectionError`], [`ConnectionStats`]).
525+
///
523526
/// Calling [`Self::closed`] keeps the connection alive until it is either closed locally via [`Connection::close`]
524-
/// or closed by the remote peer. This function instead does not keep a reference to the connection itself,
527+
/// or closed by the remote peer. This function instead does not keep the connection itself alive,
525528
/// so if all *other* clones of the connection are dropped, the connection will be closed implicitly even
526529
/// if there are futures returned from this function still being awaited.
527-
///
528-
/// Returns the reason why the connection was closed and the final [`ConnectionStats`].
529-
pub fn on_closed(
530-
&self,
531-
) -> impl Future<Output = (ConnectionError, ConnectionStats)> + Send + Sync + 'static {
530+
pub fn on_closed(&self) -> OnClosed {
532531
let (tx, rx) = oneshot::channel();
533532
self.0.state.lock("on_closed").on_closed.push(tx);
534533
OnClosed {
@@ -1056,12 +1055,14 @@ impl Future for SendDatagram<'_> {
10561055
}
10571056
}
10581057

1059-
struct OnClosed {
1058+
/// Future returned by [`Connection::on_closed`]
1059+
///
1060+
/// Resolves to a tuple of ([`ConnectionError`], [`ConnectionStats`]).
1061+
pub struct OnClosed {
10601062
rx: oneshot::Receiver<(ConnectionError, ConnectionStats)>,
10611063
conn: WeakConnectionHandle,
10621064
}
10631065

1064-
/// Future returned by [`Connection::on_closed`]
10651066
impl Drop for OnClosed {
10661067
fn drop(&mut self) {
10671068
if self.rx.is_terminated() {

quinn/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ pub use rustls;
7676
pub use udp;
7777

7878
pub use crate::connection::{
79-
AcceptBi, AcceptUni, Connecting, Connection, OpenBi, OpenUni, ReadDatagram, SendDatagram,
80-
SendDatagramError, WeakConnectionHandle, ZeroRttAccepted,
79+
AcceptBi, AcceptUni, Connecting, Connection, OnClosed, OpenBi, OpenUni, ReadDatagram,
80+
SendDatagram, SendDatagramError, WeakConnectionHandle, ZeroRttAccepted,
8181
};
8282
pub use crate::endpoint::{Accept, Endpoint, EndpointStats};
8383
pub use crate::incoming::{Incoming, IncomingFuture, RetryError};

0 commit comments

Comments
 (0)