Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow inserting into JoinMap directly #7179

Open
AlphaKeks opened this issue Feb 26, 2025 · 3 comments
Open

Allow inserting into JoinMap directly #7179

AlphaKeks opened this issue Feb 26, 2025 · 3 comments
Labels
A-tokio-util Area: The tokio-util crate C-feature-request Category: A feature request.

Comments

@AlphaKeks
Copy link

Is your feature request related to a problem? Please describe.
I'm using tokio's unstable API, mainly for tracing, and have started using tokio::task::Builder to name my long-running tasks. I now also have a use case for tokio_util::task::JoinMap, and find it unfortunate that the two do not compose. For my particular case, I'd just like to give names to the tasks in my JoinMap, but this can be generalized to other use cases as well, such as spawning a task manually in one place, and then inserting it into a JoinMap later (or conditionally).

Describe the solution you'd like
What I think would be a reasonable addition to JoinMap's public API is an explicit insert() method that takes a key and a JoinHandle.

Describe alternatives you've considered

  • leaving the API as-is, because this may not be an important feature to many people
  • adding more spawn_* methods that take a task::Builder or return their own builder type
    • this does not seem like a very good solution, as it adds way more code and is less general than what I propose, but it would fix my specific issue just as well

Additional context
JoinMap already has a private insert method that is called by spawn and friends, so the change may be as simple as making that method pub (and potentially changing the parameter type from AbortHandle to JoinHandle? unclear if that's necessary or desired).

@AlphaKeks AlphaKeks added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Feb 26, 2025
@maminrayej maminrayej added A-tokio-util Area: The tokio-util crate and removed A-tokio Area: The main tokio crate labels Feb 26, 2025
@Darksonn
Copy link
Contributor

Since JoinMap is implemented using JoinSet, this is a duplicate of #5924.

@AlphaKeks
Copy link
Author

Since JoinSet does have a build_task method (one of the alternatives I listed), should JoinMap also expose an API like that?

@Darksonn
Copy link
Contributor

That would be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-util Area: The tokio-util crate C-feature-request Category: A feature request.
Projects
None yet
Development

No branches or pull requests

3 participants