-
Notifications
You must be signed in to change notification settings - Fork 10
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
Provide helpers for common cancellation patterns #40
Comments
I thought about things like that. I think I'd prefer to write:
Opposed to the current
I've thought about adding a trait for all |
@viveksjain What do you think? |
@viveksjain I'm not sure if that's exactly your usecase, I'd value your feedback nonetheless :) |
Hmm I guess if you can use Toplevel::new()
.start_auto_shutdown("countdown", myhandler) which of course provides less flexibility (the only |
"less idiomatic/well-known" - I was hoping it was a known pattern, it's similar to OK I get your use case. Three things I struggle with:
I think the most idiomatic I could think of would be neither a new function nor a macro, but instead a wrapper struct:
where Although I think it would be easy enough to implement, so I would almost leave that to the user if he desires such a functionality. I value your 2¢ ;) |
Ah I see, I just wasn't familiar with tokio::timeout. I think select is a more common use case so it's mentioned in the guide but not sure timeout is. I think your points make a lot of sense, and I really like the AutoCancel idea. Will look into switching from my macro to something like AutoCancel. |
Now that I think about it, it would probably have to be a function instead of a struct. Or you would have to write |
Turns out this is not as easy as I thought. Maybe your macro solution has something to it after all :D |
you could always write Or you could wrap your entire subsystem in:
|
Then let's close this for now, I think I'd leave such a macro out. Maybe I'll ad it later if more people demand it, but right now it feels like too much of a corner case. If you want further discussion about things, feel free to contact me on https://discord.com/invite/tokio. |
I did get the chance to try out the beta version, and happy to say that it works great. Helped me clean up my code quite a bit. Feel free to close this issue!
One observation I will mention is that in most cases, I would like a newly started subsystem to
select!
on the parent'son_shutdown_requested
so that it shuts down immediately on error, and this was causing quite a bit of boilerplate. I was able to address it with the following macro thoughWill leave it up to you on whether such a feature makes sense to be in the lib or not (in which case it can probably be another function on
SubsystemHandle
, rather than a macro).Originally posted by @viveksjain in #37 (comment)
The text was updated successfully, but these errors were encountered: