Skip to content

Conversation

olivereanderson
Copy link
Contributor

This PR documents cancellation safety of AsyncWriteExt::flush.

Motivation

As cancellation of futures are common it is useful to know which methods are cancel safe in order to not get confused about the consequences of retrying them. This PR explains that AsyncWriteExt::flush must be cancel safe.

Solution

This PR updates the documentation to give the user more relevant information.

@Darksonn Darksonn added T-docs Topic: documentation A-tokio Area: The main tokio crate M-io Module: tokio/io labels May 27, 2025
@olivereanderson olivereanderson force-pushed the document-flush-cancel-safety branch from 576daa9 to 9bf360c Compare May 27, 2025 13:57
@Darksonn
Copy link
Contributor

Darksonn commented Jun 4, 2025

Hmm. One more suggestion. Could we add

This method is cancel safe.

As the first sentence in the docs. The current text can then come after that. With this change, I'm happy to merge this.

@olivereanderson
Copy link
Contributor Author

Hmm. One more suggestion. Could we add

This method is cancel safe.

As the first sentence in the docs. The current text can then come after that. With this change, I'm happy to merge this.

Done.

I am wondering whether the explanation should be in its own paragraph after the "This method is cancel safe" sentence or if it is OK the way it is now?

@Darksonn
Copy link
Contributor

Darksonn commented Jun 4, 2025

Having it be its own paragraph makes sense to me.

@olivereanderson
Copy link
Contributor Author

Having it be its own paragraph makes sense to me.

Placed it in its own paragraph now.

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@Darksonn Darksonn merged commit 1d98014 into tokio-rs:master Jun 8, 2025
87 checks passed
hawkw added a commit that referenced this pull request Jul 1, 2025
# 1.46.0 (July 1st, 2025)

### Fixed

- net: fixed `TcpStream::shutdown` incorrectly returning an error on macOS
  ([#7290])

## Added

- sync: `mpsc::OwnedPermit::{same_channel, same_channel_as_sender}` methods
  ([#7389])
- macros: `biased` option for `join!` and `try_join!`, similar to `select!`
  ([#7307])
- net: support for cygwin ([#7393])
- net: support `pope::OpenOptions::read_write` on Android ([#7426])
- net: add `Clone` implementation for `net::unix::SocketAddr` ([#7422])

## Changed

- runtime: eliminate unnecessary lfence while operating on `queue::Local<T>`
  ([#7340])
- task: disallow blocking in `LocalSet::{poll,drop}` ([#7372])

## Unstable

- runtime: add `TaskMeta::spawn_location` tracking where a task was spawned
  ([#7417])
- runtime: removed borrow from `LocalOptions` parameter to
  `runtime::Builder::build_local` ([#7346])

## Documented

- io: clarify behavior of seeking when `start_seek` is not used ([#7366])
- io: document cancellation safety of `AsyncWriteExt::flush` ([#7364])
- net: fix docs for `recv_buffer_size` method ([#7336])
- net: fix broken link of `RawFd` in `TcpSocket` docs ([#7416])
- net: update `AsRawFd` doc link to current Rust stdlib location ([#7429])
- readme: fix double period in reactor description (#7363)
- runtime: add doc note that `on_*_task_poll` is unstable ([#7311])
- sync: update broadcast docs on allocation failure ([#7352])
- time: add a missing panic scenario of `time::advance` ([#7394])

[#7290]: #7290
[#7307]: #7307
[#7311]: #7311
[#7336]: #7336
[#7340]: #7340
[#7346]: #7346
[#7352]: #7352
[#7364]: #7364
[#7366]: #7366
[#7372]: #7372
[#7389]: #7389
[#7393]: #7393
[#7394]: #7394
[#7416]: #7416
[#7422]: #7422
[#7426]: #7426
[#7429]: #7429
[#7417]: #7417
hawkw added a commit that referenced this pull request Jul 1, 2025
# 1.46.0 (July 1st, 2025)

### Fixed

- net: fixed `TcpStream::shutdown` incorrectly returning an error on macOS
  ([#7290])

## Added

- sync: `mpsc::OwnedPermit::{same_channel, same_channel_as_sender}` methods
  ([#7389])
- macros: `biased` option for `join!` and `try_join!`, similar to `select!`
  ([#7307])
- net: support for cygwin ([#7393])
- net: support `pope::OpenOptions::read_write` on Android ([#7426])
- net: add `Clone` implementation for `net::unix::SocketAddr` ([#7422])

## Changed

- runtime: eliminate unnecessary lfence while operating on `queue::Local<T>`
  ([#7340])
- task: disallow blocking in `LocalSet::{poll,drop}` ([#7372])

## Unstable

- runtime: add `TaskMeta::spawn_location` tracking where a task was spawned
  ([#7417])
- runtime: removed borrow from `LocalOptions` parameter to
  `runtime::Builder::build_local` ([#7346])

## Documented

- io: clarify behavior of seeking when `start_seek` is not used ([#7366])
- io: document cancellation safety of `AsyncWriteExt::flush` ([#7364])
- net: fix docs for `recv_buffer_size` method ([#7336])
- net: fix broken link of `RawFd` in `TcpSocket` docs ([#7416])
- net: update `AsRawFd` doc link to current Rust stdlib location ([#7429])
- readme: fix double period in reactor description (#7363)
- runtime: add doc note that `on_*_task_poll` is unstable ([#7311])
- sync: update broadcast docs on allocation failure ([#7352])
- time: add a missing panic scenario of `time::advance` ([#7394])

[#7290]: #7290
[#7307]: #7307
[#7311]: #7311
[#7336]: #7336
[#7340]: #7340
[#7346]: #7346
[#7352]: #7352
[#7364]: #7364
[#7366]: #7366
[#7372]: #7372
[#7389]: #7389
[#7393]: #7393
[#7394]: #7394
[#7416]: #7416
[#7422]: #7422
[#7426]: #7426
[#7429]: #7429
[#7417]: #7417
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-io Module: tokio/io T-docs Topic: documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants