Skip to content

Commit

Permalink
make API more ergonomic
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Mar 21, 2023
1 parent 8923ef1 commit 87c864f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tokio/src/io/async_fd.rs
Expand Up @@ -559,7 +559,7 @@ impl<T: AsRawFd> AsyncFd<T> {
/// let async_fd = AsyncFd::new(socket)?;
///
/// let written = async_fd
/// .async_io(Interest::WRITABLE, || async_fd.get_ref().send(&[1, 2]))
/// .async_io(Interest::WRITABLE, |inner| inner.send(&[1, 2]))
/// .await?;
///
/// println!("wrote {written} bytes");
Expand Down Expand Up @@ -596,9 +596,11 @@ impl<T: AsRawFd> AsyncFd<T> {
pub async fn async_io<R>(
&self,
interest: Interest,
f: impl FnMut() -> io::Result<R>,
mut f: impl FnMut(&T) -> io::Result<R>,
) -> io::Result<R> {
self.registration.async_io(interest, f).await
self.registration
.async_io(interest, || f(self.get_ref()))
.await
}
}

Expand Down

0 comments on commit 87c864f

Please sign in to comment.