-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
JoinHandle variant that abort on drop. #6160
Comments
Although the idea seems somewhat reasonable, I'm not convinced by the generic boolean. I would rather have a separate type. |
Thanks for the feedback. Remainders would be the type placement and the naming as implementation would be trivial. I think under
|
I think that we'd probably prefer to have something like this in Of the naming suggestions, I think |
What about |
I need this functionality too. Could this be as simple as let _guard = spawn(async {}).abort_on_drop(); It could be either setting some boolean on the existing |
I still prefer a newtype. Using the existing type makes |
I maintained The additional requirement I had that is not mentioned above is when the task is actually physically dropped. For me it was important that task is actually dropped by the time |
Tokio will never use |
This would be great to have for tests where I spawn some threads and am using .expect or .unwrap in assertions. |
wraps a `JoinHandle`, aborting the task on drop Refs: tokio-rs#6224 Fixes: tokio-rs#6160
wraps a `JoinHandle`, aborting the task on drop Refs: tokio-rs#6224 Fixes: tokio-rs#6160
wraps a `JoinHandle`, aborting the task on drop Refs: tokio-rs#6224 Fixes: tokio-rs#6160
wraps a `JoinHandle`, aborting the task on drop Refs: tokio-rs#6224 Fixes: tokio-rs#6160
wraps a `JoinHandle`, aborting the task on drop Co-authored-by: Alice Ryhl <aliceryhl@google.com> Refs: tokio-rs#6224 Fixes: tokio-rs#6160
wraps a `JoinHandle`, aborting the task on drop Co-authored-by: Alice Ryhl <aliceryhl@google.com> Refs: tokio-rs#6224 Fixes: tokio-rs#6160
Is your feature request related to a problem? Please describe.
Prior arts: #1830 #2560
After debugging few task leaks I started to make my own
JoinHandle<T>
wrapper that abort on drop and using it. It's quite useful when you understand the flow and the cancelable nature of async tasks.Describe the solution you'd like
Add const generic
bool
parameterABORT_ON_DROP
to theJoinHandle<T>
type with default valuefalse
.JoinHandle<T, true>
will.abort()
itself on itsimpl Drop
. Addfn abort_on_drop(self) -> JoinHandle<T, true>
method onJoinHandle<T, false>
to construct this type.Describe alternatives you've considered
JoinSet<T>
is nice. I'm using it when appropriate. But it's far suboptimal for fixed number of heterogeneous tasks.Like my local solution, this functionality can also be provided by separate newtype over
JoinHandle<T>
. This newtype should also impl every methods and traits theJoinHandle<T>
have. But the hardest part is naming. Honestly I can't imagine a single good name for it.Instead of having type level flag the
JoinHandle<T>
can actually holds additionalbool
flag at runtime for it. But I failed to find a good place to store it within theJoinHandle<T>
's structure.Additional context
The text was updated successfully, but these errors were encountered: