task: consider changing JoinSet
to not return cancelled JoinError
s
#4534
Labels
A-tokio
Area: The main tokio crate
C-feature-request
Category: A feature request.
M-task
Module: tokio/task
Is your feature request related to a problem? Please describe.
Currently, if a task on a
JoinSet
' is cancelled, theJoinSet
'sjoin_one
andpoll_join_one
methods will return aJoinError
withis_canceled
= true. Right now, this only occurs when theJoinSet::abort_all
method is called, or if the runtime the tasks are running on is shut down, so this is relatively infrequent --- typically, it will only once, unless theJoinSet
contains tasks spawned on multiple runtimes.However, PR #4530 introduces the ability to cancel individual tasks that are part of a
JoinSet
, without canceling the entireJoinSet
or shutting down a runtime. This means that single tasks will fail with canceledJoinError
s more frequently. I'm not really sure what the value of returning a canceledJoinError
is in this case.Describe the solution you'd like
In a "future work" comment on #4530, I suggested that we might want to change the
poll_join_one
methods to skipJoinError
s ifJoinError::is_canceled()
is true, and continue polling. This way, canceled tasks are just ignored, unless the last task in theJoinSet
was canceled (in which case, it will be empty). IMO, this makes the API somewhat simpler to use, as the user doesn't have to ignore canceled join errors while waiting for tasks on theJoinSet
to complete.Describe alternatives you've considered
Alternatively, we could...not do this. Ignoring canceled
JoinError
s does technically remove some information from the API --- the user no longer gets a confirmation that a task on the join set was canceled. However, I'm not sure if there's any strong motivation for preserving thoseJoinError
s; off the top of my head, I can't really think of a situation in which they'd be useful.The text was updated successfully, but these errors were encountered: