Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
This PR implements a builder API for
tokio_util::task::JoinMap
as discussed in #7179.Solution
JoinMap
now has a publicbuild_task
method that returns aJoinMapBuilder
.JoinMapBuilder
lets you configure a name for the task and then spawn it on theJoinMap
you originally got the builder from.Because
JoinMap
contains aJoinSet
andjoin_set::Builder
borrows itsJoinSet
mutably,join_map::Builder
cannot contain both a&mut JoinMap
(which is required for inserting the task) and ajoin_set::Builder
(which would borrowJoinMap::tasks
). I see 2 solutions to this:JoinMap::insert
in such a way that it is a free function instead of a method, and then makeBuilder
contain the individual parts ofJoinMap
that are requiredBuilder
store all the same state thatjoin_set::Builder
(ortask::Builder
for that matter) storesI chose to go with option 2, although in the future it may be better to switch to option 1, if
task::Builder
ever extends its API with callbacks and such.The
tokio_util::task::join_map
module is currently also not public, so instead of mirroringjoin_map::Builder
(where thejoin_map
module is public), theBuilder
struct is re-exported asJoinMapBuilder
. I'm not convinced this is the way to go, but making the module public would also require documenting it (which I am willing to do if desired).