Skip to content

Commit 679d765

Browse files
authored
io: document cancel safety of AsyncFd methods (#6890)
1 parent c3a9355 commit 679d765

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tokio/src/io/async_fd.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,13 @@ impl<T: AsRawFd> AsyncFd<T> {
702702
/// concurrently with other methods on this struct. This method only
703703
/// provides shared access to the inner IO resource when handling the
704704
/// [`AsyncFdReadyGuard`].
705+
///
706+
/// # Cancel safety
707+
///
708+
/// This method is cancel safe. Once a readiness event occurs, the method
709+
/// will continue to return immediately until the readiness event is
710+
/// consumed by an attempt to read or write that fails with `WouldBlock` or
711+
/// `Poll::Pending`.
705712
#[allow(clippy::needless_lifetimes)] // The lifetime improves rustdoc rendering.
706713
pub async fn readable<'a>(&'a self) -> io::Result<AsyncFdReadyGuard<'a, T>> {
707714
self.ready(Interest::READABLE).await
@@ -713,6 +720,13 @@ impl<T: AsRawFd> AsyncFd<T> {
713720
///
714721
/// This method takes `&mut self`, so it is possible to access the inner IO
715722
/// resource mutably when handling the [`AsyncFdReadyMutGuard`].
723+
///
724+
/// # Cancel safety
725+
///
726+
/// This method is cancel safe. Once a readiness event occurs, the method
727+
/// will continue to return immediately until the readiness event is
728+
/// consumed by an attempt to read or write that fails with `WouldBlock` or
729+
/// `Poll::Pending`.
716730
#[allow(clippy::needless_lifetimes)] // The lifetime improves rustdoc rendering.
717731
pub async fn readable_mut<'a>(&'a mut self) -> io::Result<AsyncFdReadyMutGuard<'a, T>> {
718732
self.ready_mut(Interest::READABLE).await
@@ -726,6 +740,13 @@ impl<T: AsRawFd> AsyncFd<T> {
726740
/// concurrently with other methods on this struct. This method only
727741
/// provides shared access to the inner IO resource when handling the
728742
/// [`AsyncFdReadyGuard`].
743+
///
744+
/// # Cancel safety
745+
///
746+
/// This method is cancel safe. Once a readiness event occurs, the method
747+
/// will continue to return immediately until the readiness event is
748+
/// consumed by an attempt to read or write that fails with `WouldBlock` or
749+
/// `Poll::Pending`.
729750
#[allow(clippy::needless_lifetimes)] // The lifetime improves rustdoc rendering.
730751
pub async fn writable<'a>(&'a self) -> io::Result<AsyncFdReadyGuard<'a, T>> {
731752
self.ready(Interest::WRITABLE).await
@@ -737,6 +758,13 @@ impl<T: AsRawFd> AsyncFd<T> {
737758
///
738759
/// This method takes `&mut self`, so it is possible to access the inner IO
739760
/// resource mutably when handling the [`AsyncFdReadyMutGuard`].
761+
///
762+
/// # Cancel safety
763+
///
764+
/// This method is cancel safe. Once a readiness event occurs, the method
765+
/// will continue to return immediately until the readiness event is
766+
/// consumed by an attempt to read or write that fails with `WouldBlock` or
767+
/// `Poll::Pending`.
740768
#[allow(clippy::needless_lifetimes)] // The lifetime improves rustdoc rendering.
741769
pub async fn writable_mut<'a>(&'a mut self) -> io::Result<AsyncFdReadyMutGuard<'a, T>> {
742770
self.ready_mut(Interest::WRITABLE).await

0 commit comments

Comments
 (0)