-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
tokio::task::JoinSet should support adding tokio::task::JoinHandles #5924
Comments
I think adding a public API method like the current I wasn't sure why we went with the current API design where futures have to be spawned by the @Darksonn, was that your intention when designing the |
So, currently the |
Hmm, I think inlining the |
Is this optimization something we want to look into? (I could be interested in taking a look). If I'm understanding this correctly, something like #6132 would not be possible if we implement this optimization right - since the handles in that iterator would have been spawned outside the context of the |
Yes ... but I would prefer if this change was made by someone who is already familiar with the |
I might take a crack at implementing this optimization in the next week or so if I have some free time. |
For clarity, is this a no to this request? |
Yes. |
** the problem **
It should be easy to spawn tasks and have them added to a JoinSet being managed in another green-thread. If JoinSets do not accept JoinHandles which are easy to pass between threads then the options are to put the JoinSet behind some kind of locking or to pass Futures to the thread where the JoinSet resides to be spawned there, which requires Boxing and Pinning the Future.
** fixing the problem **
JoinSet is simply spawning a task and inserting JoinHandle into it's internal state. I would like it to have a function that takes a JoinHandle and simply does the insert.
** the alternatives **
I can reimplement my own version of JoinSet that allows for JoinHandles, but so will anyone else wanting to use them in this way.
** context **
Allowing passing of JoinHandles means that the JoinSet can be used to do whatever has to happen whenever a task completes or panics in its own task without any performance cost in starting a new task. Alternatively using locking or passing Futures to that thread via channels will introduce a slight delay before starting each new task.
The text was updated successfully, but these errors were encountered: